monogame port
This commit is contained in:
@@ -1,286 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: ArchiveManager.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using TomShane.Neoforce.External.Zip;
|
||||
using System.Globalization;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
#region //// Classes ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// <include file='Documents/ArchiveManager.xml' path='ArchiveManager/Class[@name="ArchiveManager"]/*' />
|
||||
public class ArchiveManager : ContentManager
|
||||
{
|
||||
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private string archivePath = null;
|
||||
private ZipFile archive = null;
|
||||
private bool useArchive = false;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Properties ////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// <include file='Documents/ArchiveManager.xml' path='ArchiveManager/Member[@name="ArchivePath"]/*' />
|
||||
public virtual string ArchivePath
|
||||
{
|
||||
get { return archivePath; }
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public bool UseArchive
|
||||
{
|
||||
get { return useArchive; }
|
||||
set { useArchive = value; }
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Constructors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// <include file='Documents/ArchiveManager.xml' path='ArchiveManager/Member[@name="ArchiveManager"]/*' />
|
||||
public ArchiveManager(IServiceProvider serviceProvider) : this(serviceProvider, null) { }
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// <include file='Documents/ArchiveManager.xml' path='ArchiveManager/Member[@name="ArchiveManager1"]/*' />
|
||||
public ArchiveManager(IServiceProvider serviceProvider, string archive): base(serviceProvider)
|
||||
{
|
||||
if (archive != null)
|
||||
{
|
||||
this.archive = ZipFile.Read(archive);
|
||||
archivePath = archive;
|
||||
useArchive = true;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// <include file='Documents/ArchiveManager.xml' path='ArchiveManager/Member[@name="OpenStream"]/*' />
|
||||
protected override Stream OpenStream(string assetName)
|
||||
{
|
||||
if (useArchive && archive != null)
|
||||
{
|
||||
assetName = assetName.Replace("\\", "/");
|
||||
if (assetName.StartsWith("/")) assetName = assetName.Remove(0, 1);
|
||||
|
||||
string fullAssetName = (assetName + ".xnb").ToLower();
|
||||
|
||||
foreach (ZipEntry entry in archive)
|
||||
{
|
||||
ZipDirEntry ze = new ZipDirEntry(entry);
|
||||
|
||||
string entryName = entry.FileName.ToLower();
|
||||
|
||||
if (entryName == fullAssetName)
|
||||
{
|
||||
return entry.GetStream();
|
||||
}
|
||||
}
|
||||
throw new Exception("Cannot find asset \"" + assetName + "\" in the archive.");
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.OpenStream(assetName);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// <include file='Documents/ArchiveManager.xml' path='ArchiveManager/Member[@name="GetAssetNames"]/*' />
|
||||
public string[] GetAssetNames()
|
||||
{
|
||||
if (useArchive && archive != null)
|
||||
{
|
||||
List<string> filenames = new List<string>();
|
||||
|
||||
foreach (ZipEntry entry in archive)
|
||||
{
|
||||
string name = entry.FileName;
|
||||
if (name.EndsWith(".xnb"))
|
||||
{
|
||||
name = name.Remove(name.Length - 4, 4);
|
||||
filenames.Add(name);
|
||||
}
|
||||
}
|
||||
return filenames.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// <include file='Documents/ArchiveManager.xml' path='ArchiveManager/Member[@name="GetAssetNames1"]/*' />
|
||||
public string[] GetAssetNames(string path)
|
||||
{
|
||||
if (useArchive && archive != null)
|
||||
{
|
||||
if (path != null && path != "" && path != "\\" && path != "/")
|
||||
{
|
||||
List<string> filenames = new List<string>();
|
||||
|
||||
foreach (ZipEntry entry in archive)
|
||||
{
|
||||
string name = entry.FileName;
|
||||
if (name.EndsWith(".xnb"))
|
||||
{
|
||||
name = name.Remove(name.Length - 4, 4);
|
||||
}
|
||||
|
||||
string[] parts = name.Split('/');
|
||||
string dir = "";
|
||||
for (int i = 0; i < parts.Length - 1; i++)
|
||||
{
|
||||
dir += parts[i] + '/';
|
||||
}
|
||||
|
||||
path = path.Replace("\\", "/");
|
||||
if (path.StartsWith("/")) path = path.Remove(0, 1);
|
||||
if (!path.EndsWith("/")) path += '/';
|
||||
|
||||
if (dir.ToLower() == path.ToLower() && !name.EndsWith("/"))
|
||||
{
|
||||
filenames.Add(name);
|
||||
}
|
||||
}
|
||||
return filenames.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetAssetNames();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// <include file='Documents/ArchiveManager.xml' path='ArchiveManager/Member[@name="GetFileStream"]/*' />
|
||||
public Stream GetFileStream(string filename)
|
||||
{
|
||||
if (useArchive && archive != null)
|
||||
{
|
||||
filename = filename.Replace("\\", "/").ToLower();
|
||||
if (filename.StartsWith("/")) filename = filename.Remove(0, 1);
|
||||
|
||||
foreach (ZipEntry entry in archive)
|
||||
{
|
||||
string entryName = entry.FileName.ToLower();
|
||||
|
||||
if (entryName.Equals(filename))
|
||||
return entry.GetStream();
|
||||
}
|
||||
|
||||
throw new Exception("Cannot find file \"" + filename + "\" in the archive.");
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public string[] GetDirectories(string path)
|
||||
{
|
||||
if (useArchive && archive != null)
|
||||
{
|
||||
if (path != null && path != "" && path != "\\" && path != "/")
|
||||
{
|
||||
List<string> dirs = new List<string>();
|
||||
|
||||
path = path.Replace("\\", "/");
|
||||
if (path.StartsWith("/")) path = path.Remove(0, 1);
|
||||
if (!path.EndsWith("/")) path += '/';
|
||||
|
||||
foreach (ZipEntry entry in archive)
|
||||
{
|
||||
string name = entry.FileName;
|
||||
if (name.ToLower().StartsWith(path.ToLower()))
|
||||
{
|
||||
int i = name.IndexOf("/", path.Length);
|
||||
string item = name.Substring(path.Length, i - path.Length) + "\\";
|
||||
if (!dirs.Contains(item))
|
||||
{
|
||||
dirs.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return dirs.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetAssetNames();
|
||||
}
|
||||
}
|
||||
else if (Directory.Exists(path))
|
||||
{
|
||||
string[] dirs = Directory.GetDirectories(path);
|
||||
|
||||
for (int i = 0; i < dirs.Length; i++)
|
||||
{
|
||||
string[] parts = dirs[i].Split('\\');
|
||||
dirs[i] = parts[parts.Length - 1] + '\\';
|
||||
}
|
||||
|
||||
return dirs;
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -1,306 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: Bevel.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
#region //// Enums /////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public enum BevelStyle
|
||||
{
|
||||
None,
|
||||
Flat,
|
||||
Etched,
|
||||
Bumped,
|
||||
Lowered,
|
||||
Raised
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public enum BevelBorder
|
||||
{
|
||||
None,
|
||||
Left,
|
||||
Top,
|
||||
Right,
|
||||
Bottom,
|
||||
All
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
public class Bevel: Control
|
||||
{
|
||||
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private BevelBorder border = BevelBorder.All;
|
||||
private BevelStyle style = BevelStyle.Etched;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Properties ////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public BevelBorder Border
|
||||
{
|
||||
get { return border; }
|
||||
set
|
||||
{
|
||||
if (border != value)
|
||||
{
|
||||
border = value;
|
||||
if (!Suspended) OnBorderChanged(new EventArgs());
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public BevelStyle Style
|
||||
{
|
||||
get { return style; }
|
||||
set
|
||||
{
|
||||
if (style != value)
|
||||
{
|
||||
style = value;
|
||||
if (!Suspended) OnStyleChanged(new EventArgs());
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Events ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public event EventHandler BorderChanged;
|
||||
public event EventHandler StyleChanged;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Construstors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public Bevel(Manager manager): base(manager)
|
||||
{
|
||||
CanFocus = false;
|
||||
Passive = true;
|
||||
Width = 64;
|
||||
Height = 64;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected internal override void InitSkin()
|
||||
{
|
||||
base.InitSkin();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime)
|
||||
{
|
||||
if (Border != BevelBorder.None && Style != BevelStyle.None)
|
||||
{
|
||||
if (Border != BevelBorder.All)
|
||||
{
|
||||
DrawPart(renderer, rect, Border, Style, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawPart(renderer, rect, BevelBorder.Left, Style, true);
|
||||
DrawPart(renderer, rect, BevelBorder.Top, Style, true);
|
||||
DrawPart(renderer, rect, BevelBorder.Right, Style, true);
|
||||
DrawPart(renderer, rect, BevelBorder.Bottom, Style, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private void DrawPart(Renderer renderer, Rectangle rect, BevelBorder pos, BevelStyle style, bool all)
|
||||
{
|
||||
SkinLayer layer = Skin.Layers["Control"];
|
||||
Color c1 = Utilities.ParseColor(layer.Attributes["LightColor"].Value);
|
||||
Color c2 = Utilities.ParseColor(layer.Attributes["DarkColor"].Value);
|
||||
Color c3 = Utilities.ParseColor(layer.Attributes["FlatColor"].Value);
|
||||
|
||||
if (Color != UndefinedColor) c3 = Color;
|
||||
|
||||
Texture2D img = Skin.Layers["Control"].Image.Resource;
|
||||
|
||||
int x1 = 0; int y1 = 0; int w1 = 0; int h1 = 0;
|
||||
int x2 = 0; int y2 = 0; int w2 = 0; int h2 = 0;
|
||||
|
||||
if (style == BevelStyle.Bumped || style == BevelStyle.Etched)
|
||||
{
|
||||
if (all && (pos == BevelBorder.Top || pos == BevelBorder.Bottom))
|
||||
{
|
||||
rect = new Rectangle(rect.Left + 1, rect.Top, rect.Width - 2, rect.Height);
|
||||
}
|
||||
else if (all && (pos == BevelBorder.Left))
|
||||
{
|
||||
rect = new Rectangle(rect.Left, rect.Top, rect.Width, rect.Height - 1);
|
||||
}
|
||||
switch (pos)
|
||||
{
|
||||
case BevelBorder.Left:
|
||||
{
|
||||
x1 = rect.Left; y1 = rect.Top; w1 = 1; h1 = rect.Height;
|
||||
x2 = x1 + 1; y2 = y1; w2 = w1; h2 = h1;
|
||||
break;
|
||||
}
|
||||
case BevelBorder.Top:
|
||||
{
|
||||
x1 = rect.Left; y1 = rect.Top; w1 = rect.Width; h1 = 1;
|
||||
x2 = x1; y2 = y1 + 1; w2 = w1; h2 = h1;
|
||||
break;
|
||||
}
|
||||
case BevelBorder.Right:
|
||||
{
|
||||
x1 = rect.Left + rect.Width - 2; y1 = rect.Top; w1 = 1; h1 = rect.Height;
|
||||
x2 = x1 + 1; y2 = y1; w2 = w1; h2 = h1;
|
||||
break;
|
||||
}
|
||||
case BevelBorder.Bottom:
|
||||
{
|
||||
x1 = rect.Left; y1 = rect.Top + rect.Height - 2; w1 = rect.Width; h1 = 1;
|
||||
x2 = x1; y2 = y1 + 1; w2 = w1; h2 = h1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (pos)
|
||||
{
|
||||
case BevelBorder.Left:
|
||||
{
|
||||
x1 = rect.Left; y1 = rect.Top; w1 = 1; h1 = rect.Height;
|
||||
break;
|
||||
}
|
||||
case BevelBorder.Top:
|
||||
{
|
||||
x1 = rect.Left; y1 = rect.Top; w1 = rect.Width; h1 = 1;
|
||||
break;
|
||||
}
|
||||
case BevelBorder.Right:
|
||||
{
|
||||
x1 = rect.Left + rect.Width - 1; y1 = rect.Top; w1 = 1; h1 = rect.Height;
|
||||
break;
|
||||
}
|
||||
case BevelBorder.Bottom:
|
||||
{
|
||||
x1 = rect.Left; y1 = rect.Top + rect.Height - 1; w1 = rect.Width; h1 = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (Style)
|
||||
{
|
||||
case BevelStyle.Bumped:
|
||||
{
|
||||
renderer.Draw(img, new Rectangle(x1, y1, w1, h1), c1);
|
||||
renderer.Draw(img, new Rectangle(x2, y2, w2, h2), c2);
|
||||
break;
|
||||
}
|
||||
case BevelStyle.Etched:
|
||||
{
|
||||
renderer.Draw(img, new Rectangle(x1, y1, w1, h1), c2);
|
||||
renderer.Draw(img, new Rectangle(x2, y2, w2, h2), c1);
|
||||
break;
|
||||
}
|
||||
case BevelStyle.Raised:
|
||||
{
|
||||
Color c = c1;
|
||||
if (pos == BevelBorder.Left || pos == BevelBorder.Top) c = c1;
|
||||
else c = c2;
|
||||
|
||||
renderer.Draw(img, new Rectangle(x1, y1, w1, h1), c);
|
||||
break;
|
||||
}
|
||||
case BevelStyle.Lowered:
|
||||
{
|
||||
Color c = c1;
|
||||
if (pos == BevelBorder.Left || pos == BevelBorder.Top) c = c2;
|
||||
else c = c1;
|
||||
|
||||
renderer.Draw(img, new Rectangle(x1, y1, w1, h1), c);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
renderer.Draw(img, new Rectangle(x1, y1, w1, h1), c3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected virtual void OnBorderChanged(EventArgs e)
|
||||
{
|
||||
if (BorderChanged != null) BorderChanged.Invoke(this, e);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected virtual void OnStyleChanged(EventArgs e)
|
||||
{
|
||||
if (StyleChanged != null) StyleChanged.Invoke(this, e);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,294 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: Button.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
#region //// Enums /////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// <include file='Documents/Button.xml' path='Button/Class[@name="SizeMode"]/*' />
|
||||
public enum SizeMode
|
||||
{
|
||||
Normal,
|
||||
Auto,
|
||||
Centered,
|
||||
Stretched,
|
||||
/// <summary>
|
||||
/// Only Supported by ImageBox
|
||||
/// </summary>
|
||||
Tiled
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// <include file='Documents/Button.xml' path='Button/Class[@name="SizeMode"]/*' />
|
||||
public enum ButtonMode
|
||||
{
|
||||
Normal,
|
||||
PushButton
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Classes ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// <include file='Documents/Button.xml' path='Button/Class[@name="Glyph"]/*' />
|
||||
public class Glyph
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public Texture2D Image = null;
|
||||
public SizeMode SizeMode = SizeMode.Stretched;
|
||||
public Color Color = Color.White;
|
||||
public Point Offset = Point.Zero;
|
||||
public Rectangle SourceRect = Rectangle.Empty;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public Glyph(Texture2D image)
|
||||
{
|
||||
Image = image;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public Glyph(Texture2D image, Rectangle sourceRect): this(image)
|
||||
{
|
||||
SourceRect = sourceRect;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// <include file='Documents/Button.xml' path='Button/Class[@name="Button"]/*' />
|
||||
public class Button: ButtonBase
|
||||
{
|
||||
|
||||
#region //// Consts ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private const string skButton = "Button";
|
||||
private const string lrButton = "Control";
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private Glyph glyph = null;
|
||||
private ModalResult modalResult = ModalResult.None;
|
||||
private ButtonMode mode = ButtonMode.Normal;
|
||||
private bool pushed = false;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Properties ////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public Glyph Glyph
|
||||
{
|
||||
get { return glyph; }
|
||||
set
|
||||
{
|
||||
glyph = value;
|
||||
if (!Suspended) OnGlyphChanged(new EventArgs());
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public ModalResult ModalResult
|
||||
{
|
||||
get { return modalResult; }
|
||||
set { modalResult = value; }
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public ButtonMode Mode
|
||||
{
|
||||
get { return mode; }
|
||||
set { mode = value; }
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public bool Pushed
|
||||
{
|
||||
get { return pushed; }
|
||||
set
|
||||
{
|
||||
pushed = value;
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Events ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public event EventHandler GlyphChanged;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Construstors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public Button(Manager manager): base(manager)
|
||||
{
|
||||
SetDefaultSize(72, 24);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Destructors ///////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected internal override void InitSkin()
|
||||
{
|
||||
base.InitSkin();
|
||||
Skin = new SkinControl(Manager.Skin.Controls[skButton]);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime)
|
||||
{
|
||||
|
||||
if (mode == ButtonMode.PushButton && pushed)
|
||||
{
|
||||
SkinLayer l = Skin.Layers[lrButton];
|
||||
renderer.DrawLayer(l, rect, l.States.Pressed.Color, l.States.Pressed.Index);
|
||||
if (l.States.Pressed.Overlay)
|
||||
{
|
||||
renderer.DrawLayer(l, rect, l.Overlays.Pressed.Color, l.Overlays.Pressed.Index);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
base.DrawControl(renderer, rect, gameTime);
|
||||
}
|
||||
|
||||
SkinLayer layer = Skin.Layers[lrButton];
|
||||
SpriteFont font = (layer.Text != null && layer.Text.Font != null) ? layer.Text.Font.Resource : null;
|
||||
Color col = Color.White;
|
||||
int ox = 0; int oy = 0;
|
||||
|
||||
if (ControlState == ControlState.Pressed)
|
||||
{
|
||||
if (layer.Text != null) col = layer.Text.Colors.Pressed;
|
||||
ox = 1; oy = 1;
|
||||
}
|
||||
if (glyph != null)
|
||||
{
|
||||
Margins cont = layer.ContentMargins;
|
||||
Rectangle r = new Rectangle(rect.Left + cont.Left,
|
||||
rect.Top + cont.Top,
|
||||
rect.Width - cont.Horizontal,
|
||||
rect.Height - cont.Vertical);
|
||||
renderer.DrawGlyph(glyph, r);
|
||||
}
|
||||
else
|
||||
{
|
||||
renderer.DrawString(this, layer, Text, rect, true, ox, oy);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private void OnGlyphChanged(EventArgs e)
|
||||
{
|
||||
if (GlyphChanged != null) GlyphChanged.Invoke(this, e);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void OnClick(EventArgs e)
|
||||
{
|
||||
MouseEventArgs ex = (e is MouseEventArgs) ? (MouseEventArgs)e : new MouseEventArgs();
|
||||
|
||||
if (ex.Button == MouseButton.Left || ex.Button == MouseButton.None)
|
||||
{
|
||||
pushed = !pushed;
|
||||
}
|
||||
|
||||
base.OnClick(e);
|
||||
|
||||
if ((ex.Button == MouseButton.Left || ex.Button == MouseButton.None) && Root != null)
|
||||
{
|
||||
if (Root is Window)
|
||||
{
|
||||
Window wnd = (Window)Root;
|
||||
if (ModalResult != ModalResult.None)
|
||||
{
|
||||
wnd.Close(ModalResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: ButtonBase.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
#region //// Classes ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/// <include file='Documents/ButtonBase.xml' path='ButtonBase/Class[@name="ButtonBase"]/*' />
|
||||
public abstract class ButtonBase: Control
|
||||
{
|
||||
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Properties ////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override ControlState ControlState
|
||||
{
|
||||
get
|
||||
{
|
||||
if (DesignMode) return ControlState.Enabled;
|
||||
else if (Suspended) return ControlState.Disabled;
|
||||
else
|
||||
{
|
||||
if (!Enabled) return ControlState.Disabled;
|
||||
|
||||
if ((Pressed[(int)MouseButton.Left] && Inside) || (Focused && (Pressed[(int)GamePadActions.Press] || Pressed[(int)MouseButton.None]))) return ControlState.Pressed;
|
||||
else if (Hovered && Inside) return ControlState.Hovered;
|
||||
else if ((Focused && !Inside) || (Hovered && !Inside) || (Focused && !Hovered && Inside)) return ControlState.Focused;
|
||||
else return ControlState.Enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Events ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Construstors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected ButtonBase(Manager manager)
|
||||
: base(manager)
|
||||
{
|
||||
SetDefaultSize(72, 24);
|
||||
DoubleClicks = false;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void OnClick(EventArgs e)
|
||||
{
|
||||
MouseEventArgs ex = (e is MouseEventArgs) ? (MouseEventArgs)e : new MouseEventArgs();
|
||||
if (ex.Button == MouseButton.Left || ex.Button == MouseButton.None)
|
||||
{
|
||||
base.OnClick(e);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: CheckBox.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
using Microsoft.Xna.Framework;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
public class CheckBox: ButtonBase
|
||||
{
|
||||
|
||||
#region //// Consts ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private const string skCheckBox = "CheckBox";
|
||||
private const string lrCheckBox = "Control";
|
||||
private const string lrChecked = "Checked";
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private bool state = false;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Properties ////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual bool Checked
|
||||
{
|
||||
get
|
||||
{
|
||||
return state;
|
||||
}
|
||||
set
|
||||
{
|
||||
state = value;
|
||||
Invalidate();
|
||||
if (!Suspended) OnCheckedChanged(new EventArgs());
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Events ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public event EventHandler CheckedChanged;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Construstors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public CheckBox(Manager manager): base(manager)
|
||||
{
|
||||
CheckLayer(Skin, lrChecked);
|
||||
|
||||
Width = 64;
|
||||
Height = 16;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected internal override void InitSkin()
|
||||
{
|
||||
base.InitSkin();
|
||||
Skin = new SkinControl(Manager.Skin.Controls[skCheckBox]);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime)
|
||||
{
|
||||
SkinLayer layer = Skin.Layers[lrChecked];
|
||||
SkinText font = Skin.Layers[lrChecked].Text;
|
||||
|
||||
if (!state)
|
||||
{
|
||||
layer = Skin.Layers[lrCheckBox];
|
||||
font = Skin.Layers[lrCheckBox].Text;
|
||||
}
|
||||
|
||||
rect.Width = layer.Width;
|
||||
rect.Height = layer.Height;
|
||||
Rectangle rc = new Rectangle(rect.Left + rect.Width + 4, rect.Y, Width - (layer.Width + 4), rect.Height);
|
||||
|
||||
renderer.DrawLayer(this, layer, rect);
|
||||
renderer.DrawString(this, layer, Text, rc, false, 0, 0);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void OnClick(EventArgs e)
|
||||
{
|
||||
MouseEventArgs ex = (e is MouseEventArgs) ? (MouseEventArgs)e : new MouseEventArgs();
|
||||
|
||||
if (ex.Button == MouseButton.Left || ex.Button == MouseButton.None)
|
||||
{
|
||||
Checked = !Checked;
|
||||
}
|
||||
base.OnClick(e);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected virtual void OnCheckedChanged(EventArgs e)
|
||||
{
|
||||
if (CheckedChanged != null) CheckedChanged.Invoke(this, e);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: ClipBox.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
public class ClipBox: Control
|
||||
{
|
||||
|
||||
#region //// Constructors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public ClipBox(Manager manager): base(manager)
|
||||
{
|
||||
Color = Color.Transparent;
|
||||
BackColor = Color.Transparent;
|
||||
CanFocus = false;
|
||||
Passive = true;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime)
|
||||
{
|
||||
base.DrawControl(renderer, rect, gameTime);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,181 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: Control.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
public class ClipControl: Control
|
||||
{
|
||||
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private ClipBox clientArea;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Properties ////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual ClipBox ClientArea
|
||||
{
|
||||
get { return clientArea; }
|
||||
set { clientArea = value; }
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override Margins ClientMargins
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.ClientMargins;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.ClientMargins = value;
|
||||
if (clientArea != null)
|
||||
{
|
||||
clientArea.Left = ClientLeft;
|
||||
clientArea.Top = ClientTop;
|
||||
clientArea.Width = ClientWidth;
|
||||
clientArea.Height = ClientHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Constructors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public ClipControl(Manager manager): base(manager)
|
||||
{
|
||||
clientArea = new ClipBox(manager);
|
||||
|
||||
clientArea.Init();
|
||||
clientArea.MinimumWidth = 0;
|
||||
clientArea.MinimumHeight = 0;
|
||||
clientArea.Left = ClientLeft;
|
||||
clientArea.Top = ClientTop;
|
||||
clientArea.Width = ClientWidth;
|
||||
clientArea.Height = ClientHeight;
|
||||
|
||||
base.Add(clientArea);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected internal override void InitSkin()
|
||||
{
|
||||
base.InitSkin();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual void Add(Control control, bool client)
|
||||
{
|
||||
if (client)
|
||||
{
|
||||
clientArea.Add(control);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Add(control);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override void Add(Control control)
|
||||
{
|
||||
Add(control, true);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override void Remove(Control control)
|
||||
{
|
||||
base.Remove(control);
|
||||
clientArea.Remove(control);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected internal override void Update(GameTime gameTime)
|
||||
{
|
||||
base.Update(gameTime);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime)
|
||||
{
|
||||
base.DrawControl(renderer, rect, gameTime);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void OnResize(ResizeEventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
|
||||
if (clientArea != null)
|
||||
{
|
||||
clientArea.Left = ClientLeft;
|
||||
clientArea.Top = ClientTop;
|
||||
clientArea.Width = ClientWidth;
|
||||
clientArea.Height = ClientHeight;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected virtual void AdjustMargins()
|
||||
{
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,418 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: ComboBox.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
using System.Collections.Generic;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
public class ComboBox: TextBox
|
||||
{
|
||||
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private Button btnDown = null;
|
||||
private List<object> items = new List<object>();
|
||||
private ListBox lstCombo = null;
|
||||
private int maxItems = 5;
|
||||
private bool drawSelection = true;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Properties ////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override bool ReadOnly
|
||||
{
|
||||
get { return base.ReadOnly; }
|
||||
set
|
||||
{
|
||||
base.ReadOnly = value;
|
||||
CaretVisible = !value;
|
||||
if (value)
|
||||
{
|
||||
#if (!XBOX && !XBOX_FAKE)
|
||||
Cursor = Manager.Skin.Cursors["Default"].Resource;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if (!XBOX && !XBOX_FAKE)
|
||||
Cursor = Manager.Skin.Cursors["Text"].Resource;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public bool DrawSelection
|
||||
{
|
||||
get { return drawSelection; }
|
||||
set { drawSelection = value; }
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override string Text
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Text;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.Text = value;
|
||||
//if (!items.Contains(value)) --- bug
|
||||
if (!items.ConvertAll(item => item.ToString()).Contains(value))
|
||||
{
|
||||
ItemIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual List<object> Items
|
||||
{
|
||||
get { return items; }
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public int MaxItems
|
||||
{
|
||||
get { return maxItems; }
|
||||
set
|
||||
{
|
||||
if (maxItems != value)
|
||||
{
|
||||
maxItems = value;
|
||||
if (!Suspended) OnMaxItemsChanged(new EventArgs());
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public int ItemIndex
|
||||
{
|
||||
get { return lstCombo.ItemIndex; }
|
||||
set
|
||||
{
|
||||
if (lstCombo != null)
|
||||
{
|
||||
if (value >= 0 && value < items.Count)
|
||||
{
|
||||
lstCombo.ItemIndex = value;
|
||||
Text = lstCombo.Items[value].ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
lstCombo.ItemIndex = -1;
|
||||
}
|
||||
}
|
||||
if (!Suspended) OnItemIndexChanged(new EventArgs());
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Events ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public event EventHandler MaxItemsChanged;
|
||||
public event EventHandler ItemIndexChanged;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Construstors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public ComboBox(Manager manager): base(manager)
|
||||
{
|
||||
Height = 20;
|
||||
Width = 64;
|
||||
ReadOnly = true;
|
||||
|
||||
btnDown = new Button(Manager);
|
||||
btnDown.Init();
|
||||
btnDown.Skin = new SkinControl(Manager.Skin.Controls["ComboBox.Button"]);
|
||||
btnDown.CanFocus = false;
|
||||
btnDown.Click += new EventHandler(btnDown_Click);
|
||||
Add(btnDown, false);
|
||||
|
||||
lstCombo = new ListBox(Manager);
|
||||
lstCombo.Init();
|
||||
lstCombo.HotTrack = true;
|
||||
lstCombo.Detached = true;
|
||||
lstCombo.Visible = false;
|
||||
lstCombo.Click += new EventHandler(lstCombo_Click);
|
||||
lstCombo.FocusLost += new EventHandler(lstCombo_FocusLost);
|
||||
lstCombo.Items = items;
|
||||
manager.Input.MouseDown += new MouseEventHandler(Input_MouseDown);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Destructors ///////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// We added the listbox to another parent than this control, so we dispose it manually
|
||||
if (lstCombo != null)
|
||||
{
|
||||
lstCombo.Dispose();
|
||||
lstCombo = null;
|
||||
}
|
||||
Manager.Input.MouseDown -= Input_MouseDown;
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
lstCombo.Skin = new SkinControl(Manager.Skin.Controls["ComboBox.ListBox"]);
|
||||
|
||||
btnDown.Glyph = new Glyph(Manager.Skin.Images["Shared.ArrowDown"].Resource);
|
||||
btnDown.Glyph.Color = Manager.Skin.Controls["ComboBox.Button"].Layers["Control"].Text.Colors.Enabled;
|
||||
btnDown.Glyph.SizeMode = SizeMode.Centered;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected internal override void InitSkin()
|
||||
{
|
||||
base.InitSkin();
|
||||
Skin = new SkinControl(Manager.Skin.Controls["ComboBox"]);
|
||||
AdjustMargins();
|
||||
ReadOnly = ReadOnly; // To init the right cursor
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime)
|
||||
{
|
||||
base.DrawControl(renderer, rect, gameTime);
|
||||
|
||||
if (ReadOnly && (Focused || lstCombo.Focused) && drawSelection)
|
||||
{
|
||||
SkinLayer lr = Skin.Layers[0];
|
||||
Rectangle rc = new Rectangle(rect.Left + lr.ContentMargins.Left,
|
||||
rect.Top + lr.ContentMargins.Top,
|
||||
Width - lr.ContentMargins.Horizontal - btnDown.Width,
|
||||
Height - lr.ContentMargins.Vertical);
|
||||
renderer.Draw(Manager.Skin.Images["ListBox.Selection"].Resource, rc , Color.FromNonPremultiplied(255, 255, 255, 128));
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void OnResize(ResizeEventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
|
||||
if (btnDown != null)
|
||||
{
|
||||
btnDown.Width = 16;
|
||||
btnDown.Height = Height - Skin.Layers[0].ContentMargins.Vertical;
|
||||
btnDown.Top = Skin.Layers[0].ContentMargins.Top;
|
||||
btnDown.Left = Width - btnDown.Width - 2;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void btnDown_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (items != null && items.Count > 0)
|
||||
{
|
||||
if (this.Root != null && this.Root is Container)
|
||||
{
|
||||
(this.Root as Container).Add(lstCombo, false);
|
||||
lstCombo.Alpha = Root.Alpha;
|
||||
lstCombo.Left = AbsoluteLeft - Root.Left;
|
||||
lstCombo.Top = AbsoluteTop - Root.Top + Height + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
Manager.Add(lstCombo);
|
||||
lstCombo.Alpha = Alpha;
|
||||
lstCombo.Left = AbsoluteLeft;
|
||||
lstCombo.Top = AbsoluteTop + Height + 1;
|
||||
}
|
||||
|
||||
lstCombo.AutoHeight(maxItems);
|
||||
if (lstCombo.AbsoluteTop + lstCombo.Height > Manager.TargetHeight)
|
||||
{
|
||||
lstCombo.Top = lstCombo.Top - Height - lstCombo.Height - 2;
|
||||
}
|
||||
|
||||
lstCombo.Visible = !lstCombo.Visible;
|
||||
lstCombo.Focused = true;
|
||||
lstCombo.Width = Width;
|
||||
lstCombo.AutoHeight(maxItems);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void Input_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (ReadOnly &&
|
||||
(e.Position.X >= AbsoluteLeft &&
|
||||
e.Position.X <= AbsoluteLeft + Width &&
|
||||
e.Position.Y >= AbsoluteTop &&
|
||||
e.Position.Y <= AbsoluteTop + Height)) return;
|
||||
|
||||
if (lstCombo.Visible &&
|
||||
(e.Position.X < lstCombo.AbsoluteLeft ||
|
||||
e.Position.X > lstCombo.AbsoluteLeft + lstCombo.Width ||
|
||||
e.Position.Y < lstCombo.AbsoluteTop ||
|
||||
e.Position.Y > lstCombo.AbsoluteTop + lstCombo.Height) &&
|
||||
(e.Position.X < btnDown.AbsoluteLeft ||
|
||||
e.Position.X > btnDown.AbsoluteLeft + btnDown.Width ||
|
||||
e.Position.Y < btnDown.AbsoluteTop ||
|
||||
e.Position.Y > btnDown.AbsoluteTop + btnDown.Height))
|
||||
{
|
||||
//lstCombo.Visible = false;
|
||||
btnDown_Click(sender, e);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void lstCombo_Click(object sender, EventArgs e)
|
||||
{
|
||||
MouseEventArgs ex = (e is MouseEventArgs) ? (MouseEventArgs)e : new MouseEventArgs();
|
||||
|
||||
if (ex.Button == MouseButton.Left || ex.Button == MouseButton.None)
|
||||
{
|
||||
lstCombo.Visible = false;
|
||||
if (lstCombo.ItemIndex >= 0)
|
||||
{
|
||||
Text = lstCombo.Items[lstCombo.ItemIndex].ToString();
|
||||
Focused = true;
|
||||
ItemIndex = lstCombo.ItemIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Keys.Down)
|
||||
{
|
||||
e.Handled = true;
|
||||
btnDown_Click(this, new MouseEventArgs());
|
||||
}
|
||||
base.OnKeyDown(e);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void OnGamePadDown(GamePadEventArgs e)
|
||||
{
|
||||
if (!e.Handled)
|
||||
{
|
||||
if (e.Button == GamePadActions.Click || e.Button == GamePadActions.Press || e.Button == GamePadActions.Down)
|
||||
{
|
||||
e.Handled = true;
|
||||
btnDown_Click(this, new MouseEventArgs());
|
||||
}
|
||||
}
|
||||
base.OnGamePadDown(e);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void OnMouseDown(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
|
||||
if (ReadOnly && e.Button == MouseButton.Left)
|
||||
{
|
||||
btnDown_Click(this, new MouseEventArgs());
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected virtual void OnMaxItemsChanged(EventArgs e)
|
||||
{
|
||||
if (MaxItemsChanged != null) MaxItemsChanged.Invoke(this, e);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected virtual void OnItemIndexChanged(EventArgs e)
|
||||
{
|
||||
if (ItemIndexChanged != null) ItemIndexChanged.Invoke(this, e);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void lstCombo_FocusLost(object sender, EventArgs e)
|
||||
{
|
||||
//lstCombo.Visible = false;
|
||||
Invalidate();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void AdjustMargins()
|
||||
{
|
||||
base.AdjustMargins();
|
||||
ClientMargins = new Margins(ClientMargins.Left, ClientMargins.Top, ClientMargins.Right + 16, ClientMargins.Bottom);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: Component.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
public class Component: Disposable
|
||||
{
|
||||
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private Manager manager = null;
|
||||
private bool initialized = false;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Properties ////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual Manager Manager { get { return manager; } set { manager = value; } }
|
||||
public virtual bool Initialized { get { return initialized; } }
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Constructors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public Component(Manager manager)
|
||||
{
|
||||
if (manager != null)
|
||||
{
|
||||
this.manager = manager;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Component cannot be created. Manager instance is needed.");
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Destructors ///////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual void Init()
|
||||
{
|
||||
initialized = true;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected internal virtual void Update(GameTime gameTime)
|
||||
{
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,593 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: Console.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
public struct ConsoleMessage
|
||||
{
|
||||
public string Text;
|
||||
public byte Channel;
|
||||
public DateTime Time;
|
||||
public string Sender;
|
||||
|
||||
public ConsoleMessage(string sender, string text, byte channel)
|
||||
{
|
||||
this.Text = text;
|
||||
this.Channel = channel;
|
||||
this.Time = DateTime.Now;
|
||||
this.Sender = sender;
|
||||
}
|
||||
}
|
||||
|
||||
public class ChannelList : EventedList<ConsoleChannel>
|
||||
{
|
||||
|
||||
#region //// Indexers //////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public ConsoleChannel this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
for (int i = 0; i < this.Count; i++)
|
||||
{
|
||||
ConsoleChannel s = (ConsoleChannel)this[i];
|
||||
if (s.Name.ToLower() == name.ToLower())
|
||||
{
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return default(ConsoleChannel);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
for (int i = 0; i < this.Count; i++)
|
||||
{
|
||||
ConsoleChannel s = (ConsoleChannel)this[i];
|
||||
if (s.Name.ToLower() == name.ToLower())
|
||||
{
|
||||
this[i] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public ConsoleChannel this[byte index]
|
||||
{
|
||||
get
|
||||
{
|
||||
for (int i = 0; i < this.Count; i++)
|
||||
{
|
||||
ConsoleChannel s = (ConsoleChannel)this[i];
|
||||
if (s.Index == index)
|
||||
{
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return default(ConsoleChannel);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
for (int i = 0; i < this.Count; i++)
|
||||
{
|
||||
ConsoleChannel s = (ConsoleChannel)this[i];
|
||||
if (s.Index == index)
|
||||
{
|
||||
this[i] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
public class ConsoleChannel
|
||||
{
|
||||
private string name;
|
||||
private byte index;
|
||||
private Color color;
|
||||
|
||||
public ConsoleChannel(byte index, string name, Color color)
|
||||
{
|
||||
this.name = name;
|
||||
this.index = index;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public virtual byte Index
|
||||
{
|
||||
get { return index; }
|
||||
set { index = value; }
|
||||
}
|
||||
|
||||
public virtual Color Color
|
||||
{
|
||||
get { return color; }
|
||||
set { color = value; }
|
||||
}
|
||||
|
||||
public virtual string Name
|
||||
{
|
||||
get { return name; }
|
||||
set { name = value; }
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum ConsoleMessageFormats
|
||||
{
|
||||
None = 0x00,
|
||||
ChannelName = 0x01,
|
||||
TimeStamp = 0x02,
|
||||
Sender = 0x03,
|
||||
All = Sender | ChannelName | TimeStamp
|
||||
}
|
||||
|
||||
public class Console : Container
|
||||
{
|
||||
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private TextBox txtMain = null;
|
||||
private ComboBox cmbMain;
|
||||
private EventedList<ConsoleMessage> buffer = new EventedList<ConsoleMessage>();
|
||||
private ChannelList channels = new ChannelList();
|
||||
private List<byte> filter = new List<byte>();
|
||||
private ConsoleMessageFormats messageFormat = ConsoleMessageFormats.None;
|
||||
private bool channelsVisible = true;
|
||||
private bool textBoxVisible = true;
|
||||
private string sender;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Properties ////////
|
||||
|
||||
public string Sender
|
||||
{
|
||||
get { return sender; }
|
||||
set { sender = value; }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual EventedList<ConsoleMessage> MessageBuffer
|
||||
{
|
||||
get { return buffer; }
|
||||
set
|
||||
{
|
||||
buffer.ItemAdded -= new EventHandler(buffer_ItemAdded);
|
||||
buffer = value;
|
||||
buffer.ItemAdded += new EventHandler(buffer_ItemAdded);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual ChannelList Channels
|
||||
{
|
||||
get { return channels; }
|
||||
set
|
||||
{
|
||||
channels.ItemAdded -= new EventHandler(channels_ItemAdded);
|
||||
channels = value;
|
||||
channels.ItemAdded += new EventHandler(channels_ItemAdded);
|
||||
channels_ItemAdded(null, null);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual List<byte> ChannelFilter
|
||||
{
|
||||
get { return filter; }
|
||||
set { filter = value; }
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual byte SelectedChannel
|
||||
{
|
||||
set { cmbMain.Text = channels[value].Name; }
|
||||
get { return channels[cmbMain.Text].Index; }
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual ConsoleMessageFormats MessageFormat
|
||||
{
|
||||
get { return messageFormat; }
|
||||
set { messageFormat = value; }
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual bool ChannelsVisible
|
||||
{
|
||||
get { return channelsVisible; }
|
||||
set
|
||||
{
|
||||
cmbMain.Visible = channelsVisible = value;
|
||||
if (value && !textBoxVisible) TextBoxVisible = false;
|
||||
PositionControls();
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual bool TextBoxVisible
|
||||
{
|
||||
get { return textBoxVisible; }
|
||||
set
|
||||
{
|
||||
txtMain.Visible = textBoxVisible = value;
|
||||
txtMain.Focused = true;
|
||||
if (!value && channelsVisible) ChannelsVisible = false;
|
||||
PositionControls();
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Events ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public event ConsoleMessageEventHandler MessageSent;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Construstors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public Console(Manager manager)
|
||||
: base(manager)
|
||||
{
|
||||
Width = 320;
|
||||
Height = 160;
|
||||
MinimumHeight = 64;
|
||||
MinimumWidth = 64;
|
||||
CanFocus = false;
|
||||
Resizable = false;
|
||||
Movable = false;
|
||||
|
||||
cmbMain = new ComboBox(manager);
|
||||
cmbMain.Init();
|
||||
cmbMain.Top = Height - cmbMain.Height;
|
||||
cmbMain.Left = 0;
|
||||
cmbMain.Width = 128;
|
||||
cmbMain.Anchor = Anchors.Left | Anchors.Bottom;
|
||||
cmbMain.Detached = false;
|
||||
cmbMain.DrawSelection = false;
|
||||
cmbMain.Visible = channelsVisible;
|
||||
Add(cmbMain, false);
|
||||
|
||||
txtMain = new TextBox(manager);
|
||||
txtMain.Init();
|
||||
txtMain.Top = Height - txtMain.Height;
|
||||
txtMain.Left = cmbMain.Width + 1;
|
||||
txtMain.Anchor = Anchors.Left | Anchors.Bottom | Anchors.Right;
|
||||
txtMain.Detached = false;
|
||||
txtMain.Visible = textBoxVisible;
|
||||
txtMain.KeyDown += new KeyEventHandler(txtMain_KeyDown);
|
||||
txtMain.GamePadDown += new GamePadEventHandler(txtMain_GamePadDown);
|
||||
txtMain.FocusGained += new EventHandler(txtMain_FocusGained);
|
||||
Add(txtMain, false);
|
||||
|
||||
VerticalScrollBar.Top = 2;
|
||||
VerticalScrollBar.Left = Width - 18;
|
||||
VerticalScrollBar.Range = 1;
|
||||
VerticalScrollBar.PageSize = 1;
|
||||
VerticalScrollBar.ValueChanged += new EventHandler(VerticalScrollBar_ValueChanged);
|
||||
VerticalScrollBar.Visible = true;
|
||||
|
||||
ClientArea.Draw += new DrawEventHandler(ClientArea_Draw);
|
||||
|
||||
buffer.ItemAdded += new EventHandler(buffer_ItemAdded);
|
||||
channels.ItemAdded += new EventHandler(channels_ItemAdded);
|
||||
channels.ItemRemoved += new EventHandler(channels_ItemRemoved);
|
||||
|
||||
PositionControls();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private void PositionControls()
|
||||
{
|
||||
if (txtMain != null)
|
||||
{
|
||||
txtMain.Left = channelsVisible ? cmbMain.Width + 1 : 0;
|
||||
txtMain.Width = channelsVisible ? Width - cmbMain.Width - 1 : Width;
|
||||
|
||||
if (textBoxVisible)
|
||||
{
|
||||
ClientMargins = new Margins(Skin.ClientMargins.Left, Skin.ClientMargins.Top + 4, VerticalScrollBar.Width + 6, txtMain.Height + 4);
|
||||
VerticalScrollBar.Height = Height - txtMain.Height - 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
ClientMargins = new Margins(Skin.ClientMargins.Left, Skin.ClientMargins.Top + 4, VerticalScrollBar.Width + 6, 2);
|
||||
VerticalScrollBar.Height = Height - 4;
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected internal override void InitSkin()
|
||||
{
|
||||
base.InitSkin();
|
||||
Skin = new SkinControl(Manager.Skin.Controls["Console"]);
|
||||
|
||||
PositionControls();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected internal override void Update(GameTime gameTime)
|
||||
{
|
||||
base.Update(gameTime);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void ClientArea_Draw(object sender, DrawEventArgs e)
|
||||
{
|
||||
SpriteFont font = Skin.Layers[0].Text.Font.Resource;
|
||||
Rectangle r = new Rectangle(e.Rectangle.Left, e.Rectangle.Top, e.Rectangle.Width, e.Rectangle.Height);
|
||||
int pos = 0;
|
||||
|
||||
if (buffer.Count > 0)
|
||||
{
|
||||
EventedList<ConsoleMessage> b = GetFilteredBuffer(filter);
|
||||
int c = b.Count;
|
||||
int s = (VerticalScrollBar.Value + VerticalScrollBar.PageSize);
|
||||
int f = s - VerticalScrollBar.PageSize;
|
||||
|
||||
if (b.Count > 0)
|
||||
{
|
||||
for (int i = s - 1; i >= f; i--)
|
||||
{
|
||||
{
|
||||
int x = 4;
|
||||
int y = r.Bottom - (pos + 1) * ((int)font.LineSpacing + 0);
|
||||
|
||||
string msg = ((ConsoleMessage)b[i]).Text;
|
||||
string pre = "";
|
||||
ConsoleChannel ch = (channels[((ConsoleMessage)b[i]).Channel] as ConsoleChannel);
|
||||
|
||||
if ((messageFormat & ConsoleMessageFormats.ChannelName) == ConsoleMessageFormats.ChannelName)
|
||||
{
|
||||
pre += string.Format("[{0}]", channels[((ConsoleMessage)b[i]).Channel].Name);
|
||||
}
|
||||
if ((messageFormat & ConsoleMessageFormats.Sender) == ConsoleMessageFormats.Sender)
|
||||
{
|
||||
pre += string.Format("[{0}]", ((ConsoleMessage)b[i]).Sender);
|
||||
}
|
||||
if ((messageFormat & ConsoleMessageFormats.TimeStamp) == ConsoleMessageFormats.TimeStamp)
|
||||
{
|
||||
pre = string.Format("[{0}]", ((ConsoleMessage)b[i]).Time.ToLongTimeString()) + pre;
|
||||
}
|
||||
|
||||
if (pre != "") msg = pre + ": " + msg;
|
||||
|
||||
e.Renderer.DrawString(font,
|
||||
msg,
|
||||
x, y,
|
||||
ch.Color);
|
||||
pos += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime)
|
||||
{
|
||||
int h = txtMain.Visible ? (txtMain.Height + 1) : 0;
|
||||
Rectangle r = new Rectangle(rect.Left, rect.Top, rect.Width, rect.Height - h);
|
||||
base.DrawControl(renderer, r, gameTime);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void txtMain_FocusGained(object sender, EventArgs e)
|
||||
{
|
||||
ConsoleChannel ch = channels[cmbMain.Text];
|
||||
if (ch != null) txtMain.TextColor = ch.Color;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void txtMain_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
SendMessage(e);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void txtMain_GamePadDown(object sender, GamePadEventArgs e)
|
||||
{
|
||||
SendMessage(e);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private void SendMessage(EventArgs x)
|
||||
{
|
||||
KeyEventArgs k = new KeyEventArgs();
|
||||
GamePadEventArgs g = new GamePadEventArgs(PlayerIndex.One);
|
||||
|
||||
if (x is KeyEventArgs) k = x as KeyEventArgs;
|
||||
else if (x is GamePadEventArgs) g = x as GamePadEventArgs;
|
||||
|
||||
ConsoleChannel ch = channels[cmbMain.Text];
|
||||
if (ch != null)
|
||||
{
|
||||
txtMain.TextColor = ch.Color;
|
||||
|
||||
string message = txtMain.Text;
|
||||
if ((k.Key == Microsoft.Xna.Framework.Input.Keys.Enter || g.Button == GamePadActions.Press) && message != null && message != "")
|
||||
{
|
||||
x.Handled = true;
|
||||
|
||||
ConsoleMessageEventArgs me = new ConsoleMessageEventArgs(new ConsoleMessage(sender, message, ch.Index));
|
||||
OnMessageSent(me);
|
||||
|
||||
buffer.Add(new ConsoleMessage(sender, me.Message.Text, me.Message.Channel));
|
||||
|
||||
txtMain.Text = "";
|
||||
ClientArea.Invalidate();
|
||||
|
||||
CalcScrolling();
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected virtual void OnMessageSent(ConsoleMessageEventArgs e)
|
||||
{
|
||||
if (MessageSent != null) MessageSent.Invoke(this, e);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void channels_ItemAdded(object sender, EventArgs e)
|
||||
{
|
||||
cmbMain.Items.Clear();
|
||||
for (int i = 0; i < channels.Count; i++)
|
||||
{
|
||||
cmbMain.Items.Add((channels[i] as ConsoleChannel).Name);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void channels_ItemRemoved(object sender, EventArgs e)
|
||||
{
|
||||
cmbMain.Items.Clear();
|
||||
for (int i = 0; i < channels.Count; i++)
|
||||
{
|
||||
cmbMain.Items.Add((channels[i] as ConsoleChannel).Name);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void buffer_ItemAdded(object sender, EventArgs e)
|
||||
{
|
||||
CalcScrolling();
|
||||
ClientArea.Invalidate();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private void CalcScrolling()
|
||||
{
|
||||
if (VerticalScrollBar != null)
|
||||
{
|
||||
int line = Skin.Layers[0].Text.Font.Resource.LineSpacing;
|
||||
int c = GetFilteredBuffer(filter).Count;
|
||||
int p = (int)Math.Ceiling(ClientArea.ClientHeight / (float)line);
|
||||
|
||||
VerticalScrollBar.Range = c == 0 ? 1 : c;
|
||||
VerticalScrollBar.PageSize = c == 0 ? 1 : p;
|
||||
VerticalScrollBar.Value = VerticalScrollBar.Range;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void VerticalScrollBar_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
ClientArea.Invalidate();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void OnResize(ResizeEventArgs e)
|
||||
{
|
||||
CalcScrolling();
|
||||
base.OnResize(e);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private EventedList<ConsoleMessage> GetFilteredBuffer(List<byte> filter)
|
||||
{
|
||||
EventedList<ConsoleMessage> ret = new EventedList<ConsoleMessage>();
|
||||
|
||||
if (filter.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < buffer.Count; i++)
|
||||
{
|
||||
if (filter.Contains(((ConsoleMessage)buffer[i]).Channel))
|
||||
{
|
||||
ret.Add(buffer[i]);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
else return buffer;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,554 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: Container.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
public struct ScrollBarValue
|
||||
{
|
||||
public int Vertical;
|
||||
public int Horizontal;
|
||||
}
|
||||
|
||||
public class Container: ClipControl
|
||||
{
|
||||
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private ScrollBar sbVert;
|
||||
private ScrollBar sbHorz;
|
||||
private MainMenu mainMenu;
|
||||
private ToolBarPanel toolBarPanel;
|
||||
private StatusBar statusBar;
|
||||
private bool autoScroll = false;
|
||||
private Control defaultControl = null;
|
||||
|
||||
/// <summary>
|
||||
/// Scroll by PageSize (true) or StepSize (false)
|
||||
/// </summary>
|
||||
private bool scrollAlot = true;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Properties ////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual ScrollBarValue ScrollBarValue
|
||||
{
|
||||
get
|
||||
{
|
||||
ScrollBarValue scb = new ScrollBarValue();
|
||||
scb.Vertical = (sbVert != null ? sbVert.Value : 0);
|
||||
scb.Horizontal = (sbHorz != null ? sbHorz.Value : 0);
|
||||
return scb;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override bool Visible
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Visible;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
if (DefaultControl != null)
|
||||
{
|
||||
DefaultControl.Focused = true;
|
||||
}
|
||||
}
|
||||
base.Visible = value;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual Control DefaultControl
|
||||
{
|
||||
get { return defaultControl; }
|
||||
set { defaultControl = value; }
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual bool AutoScroll
|
||||
{
|
||||
get { return autoScroll; }
|
||||
set { autoScroll = value; }
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual MainMenu MainMenu
|
||||
{
|
||||
get { return mainMenu; }
|
||||
set
|
||||
{
|
||||
if (mainMenu != null)
|
||||
{
|
||||
mainMenu.Resize -= Bars_Resize;
|
||||
Remove(mainMenu);
|
||||
}
|
||||
mainMenu = value;
|
||||
|
||||
if (mainMenu != null)
|
||||
{
|
||||
Add(mainMenu, false);
|
||||
mainMenu.Resize += Bars_Resize;
|
||||
}
|
||||
AdjustMargins();
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual ToolBarPanel ToolBarPanel
|
||||
{
|
||||
get
|
||||
{
|
||||
return toolBarPanel;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (toolBarPanel != null)
|
||||
{
|
||||
toolBarPanel.Resize -= Bars_Resize;
|
||||
Remove(toolBarPanel);
|
||||
}
|
||||
toolBarPanel = value;
|
||||
|
||||
if (toolBarPanel != null)
|
||||
{
|
||||
Add(toolBarPanel, false);
|
||||
toolBarPanel.Resize += Bars_Resize;
|
||||
}
|
||||
AdjustMargins();
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual StatusBar StatusBar
|
||||
{
|
||||
get
|
||||
{
|
||||
return statusBar;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (statusBar != null)
|
||||
{
|
||||
statusBar.Resize -= Bars_Resize;
|
||||
Remove(statusBar);
|
||||
}
|
||||
statusBar = value;
|
||||
|
||||
if (statusBar != null)
|
||||
{
|
||||
Add(statusBar, false);
|
||||
statusBar.Resize += Bars_Resize;
|
||||
}
|
||||
AdjustMargins();
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// <summary>
|
||||
/// Scroll by PageSize (true) or StepSize (false)
|
||||
/// </summary>
|
||||
public virtual bool ScrollAlot
|
||||
{
|
||||
get { return this.scrollAlot; }
|
||||
set { this.scrollAlot = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the container's vertical scroll bar.
|
||||
/// </summary>
|
||||
protected virtual ScrollBar VerticalScrollBar
|
||||
{
|
||||
get { return this.sbVert; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the container's horizontal scroll bar.
|
||||
/// </summary>
|
||||
protected virtual ScrollBar HorizontalScrollBar
|
||||
{
|
||||
get { return this.sbHorz; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Constructors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public Container(Manager manager): base(manager)
|
||||
{
|
||||
sbVert = new ScrollBar(manager, Orientation.Vertical);
|
||||
sbVert.Init();
|
||||
sbVert.Detached = false;
|
||||
sbVert.Anchor = Anchors.Top | Anchors.Right | Anchors.Bottom;
|
||||
sbVert.ValueChanged += new EventHandler(ScrollBarValueChanged);
|
||||
sbVert.Range = 0;
|
||||
sbVert.PageSize = 0;
|
||||
sbVert.Value = 0;
|
||||
sbVert.Visible = false;
|
||||
|
||||
sbHorz = new ScrollBar(manager, Orientation.Horizontal);
|
||||
sbHorz.Init();
|
||||
sbHorz.Detached = false;
|
||||
sbHorz.Anchor = Anchors.Right | Anchors.Left | Anchors.Bottom;
|
||||
sbHorz.ValueChanged += new EventHandler(ScrollBarValueChanged);
|
||||
sbHorz.Range = 0;
|
||||
sbHorz.PageSize = 0;
|
||||
sbHorz.Value = 0;
|
||||
sbHorz.Visible = false;
|
||||
|
||||
Add(sbVert, false);
|
||||
Add(sbHorz, false);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected internal override void InitSkin()
|
||||
{
|
||||
base.InitSkin();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private void Bars_Resize(object sender, ResizeEventArgs e)
|
||||
{
|
||||
AdjustMargins();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void AdjustMargins()
|
||||
{
|
||||
Margins m = Skin.ClientMargins;
|
||||
|
||||
if (this.GetType() != typeof(Container))
|
||||
{
|
||||
m = ClientMargins;
|
||||
}
|
||||
|
||||
if (mainMenu != null && mainMenu.Visible)
|
||||
{
|
||||
if (!mainMenu.Initialized) mainMenu.Init();
|
||||
mainMenu.Left = m.Left;
|
||||
mainMenu.Top = m.Top;
|
||||
mainMenu.Width = Width - m.Horizontal;
|
||||
mainMenu.Anchor = Anchors.Left | Anchors.Top | Anchors.Right;
|
||||
|
||||
m.Top += mainMenu.Height;
|
||||
}
|
||||
if (toolBarPanel != null && toolBarPanel.Visible)
|
||||
{
|
||||
if (!toolBarPanel.Initialized) toolBarPanel.Init();
|
||||
toolBarPanel.Left = m.Left;
|
||||
toolBarPanel.Top = m.Top;
|
||||
toolBarPanel.Width = Width - m.Horizontal;
|
||||
toolBarPanel.Anchor = Anchors.Left | Anchors.Top | Anchors.Right;
|
||||
|
||||
m.Top += toolBarPanel.Height;
|
||||
}
|
||||
if (statusBar != null && statusBar.Visible)
|
||||
{
|
||||
if (!statusBar.Initialized) statusBar.Init();
|
||||
statusBar.Left = m.Left;
|
||||
statusBar.Top = Height - m.Bottom - statusBar.Height;
|
||||
statusBar.Width = Width - m.Horizontal;
|
||||
statusBar.Anchor = Anchors.Left | Anchors.Bottom | Anchors.Right;
|
||||
|
||||
m.Bottom += statusBar.Height;
|
||||
}
|
||||
if (sbVert != null && sbVert.Visible)
|
||||
{
|
||||
m.Right += (sbVert.Width + 2);
|
||||
}
|
||||
if (sbHorz != null && sbHorz.Visible)
|
||||
{
|
||||
m.Bottom += (sbHorz.Height + 2);
|
||||
}
|
||||
|
||||
ClientMargins = m;
|
||||
|
||||
PositionScrollBars();
|
||||
|
||||
base.AdjustMargins();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override void Add(Control control, bool client)
|
||||
{
|
||||
base.Add(control, client);
|
||||
CalcScrolling();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected internal override void Update(GameTime gameTime)
|
||||
{
|
||||
base.Update(gameTime);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime)
|
||||
{
|
||||
base.DrawControl(renderer, rect, gameTime);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected internal override void OnSkinChanged(EventArgs e)
|
||||
{
|
||||
base.OnSkinChanged(e);
|
||||
if (sbVert != null && sbHorz != null)
|
||||
{
|
||||
sbVert.Visible = false;
|
||||
sbHorz.Visible = false;
|
||||
CalcScrolling();
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private void PositionScrollBars()
|
||||
{
|
||||
if (sbVert != null)
|
||||
{
|
||||
sbVert.Left = ClientLeft + ClientWidth + 1;
|
||||
sbVert.Top = ClientTop + 1;
|
||||
int m = (sbHorz != null && sbHorz.Visible) ? 0 : 2;
|
||||
sbVert.Height = ClientArea.Height - m;
|
||||
sbVert.Range = ClientArea.VirtualHeight;
|
||||
sbVert.PageSize = ClientArea.ClientHeight;
|
||||
}
|
||||
|
||||
if (sbHorz != null)
|
||||
{
|
||||
sbHorz.Left = ClientLeft + 1;
|
||||
sbHorz.Top = ClientTop + ClientHeight + 1;
|
||||
int m = (sbVert != null && sbVert.Visible) ? 0 : 2;
|
||||
sbHorz.Width = ClientArea.Width - m;
|
||||
sbHorz.Range = ClientArea.VirtualWidth;
|
||||
sbHorz.PageSize = ClientArea.ClientWidth;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private void CalcScrolling()
|
||||
{
|
||||
if (sbVert != null && autoScroll)
|
||||
{
|
||||
bool vis = sbVert.Visible;
|
||||
sbVert.Visible = ClientArea.VirtualHeight > ClientArea.ClientHeight;
|
||||
if (ClientArea.VirtualHeight <= ClientArea.ClientHeight) sbVert.Value = 0;
|
||||
|
||||
if (vis != sbVert.Visible)
|
||||
{
|
||||
if (!sbVert.Visible)
|
||||
{
|
||||
foreach (Control c in ClientArea.Controls)
|
||||
{
|
||||
c.TopModifier = 0;
|
||||
c.Invalidate();
|
||||
}
|
||||
}
|
||||
AdjustMargins();
|
||||
}
|
||||
|
||||
PositionScrollBars();
|
||||
foreach (Control c in ClientArea.Controls)
|
||||
{
|
||||
c.TopModifier = -sbVert.Value;
|
||||
c.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
if (sbHorz != null && autoScroll)
|
||||
{
|
||||
bool vis = sbHorz.Visible;
|
||||
sbHorz.Visible = ClientArea.VirtualWidth > ClientArea.ClientWidth;
|
||||
if (ClientArea.VirtualWidth <= ClientArea.ClientWidth) sbHorz.Value = 0;
|
||||
|
||||
if (vis != sbHorz.Visible)
|
||||
{
|
||||
if (!sbHorz.Visible)
|
||||
{
|
||||
foreach (Control c in ClientArea.Controls)
|
||||
{
|
||||
c.LeftModifier = 0;
|
||||
sbVert.Refresh();
|
||||
c.Invalidate();
|
||||
}
|
||||
}
|
||||
AdjustMargins();
|
||||
}
|
||||
|
||||
PositionScrollBars();
|
||||
foreach (Control c in ClientArea.Controls)
|
||||
{
|
||||
c.LeftModifier = -sbHorz.Value;
|
||||
sbHorz.Refresh();
|
||||
c.Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual void ScrollTo(int x, int y)
|
||||
{
|
||||
sbVert.Value = y;
|
||||
sbHorz.Value = x;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual void ScrollTo(Control control)
|
||||
{
|
||||
if (control != null && ClientArea != null && ClientArea.Contains(control, true))
|
||||
{
|
||||
if (control.AbsoluteTop + control.Height > ClientArea.AbsoluteTop + ClientArea.Height)
|
||||
{
|
||||
sbVert.Value = sbVert.Value + control.AbsoluteTop - ClientArea.AbsoluteTop - sbVert.PageSize + control.Height;
|
||||
}
|
||||
else if (control.AbsoluteTop < ClientArea.AbsoluteTop)
|
||||
{
|
||||
sbVert.Value = sbVert.Value + control.AbsoluteTop - ClientArea.AbsoluteTop;
|
||||
}
|
||||
if (control.AbsoluteLeft + control.Width > ClientArea.AbsoluteLeft + ClientArea.Width)
|
||||
{
|
||||
sbHorz.Value = sbHorz.Value + control.AbsoluteLeft - ClientArea.AbsoluteLeft - sbHorz.PageSize + control.Width;
|
||||
}
|
||||
else if (control.AbsoluteLeft < ClientArea.AbsoluteLeft)
|
||||
{
|
||||
sbHorz.Value = sbHorz.Value + control.AbsoluteLeft - ClientArea.AbsoluteLeft;
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void ScrollBarValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
CalcScrolling();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void OnResize(ResizeEventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
CalcScrolling();
|
||||
|
||||
// Crappy fix to certain scrolling issue
|
||||
//if (sbVert != null) sbVert.Value -= 1;
|
||||
//if (sbHorz != null) sbHorz.Value -= 1;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override void Invalidate()
|
||||
{
|
||||
base.Invalidate();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void OnClick(EventArgs e)
|
||||
{
|
||||
MouseEventArgs ex = e as MouseEventArgs;
|
||||
ex.Position = new Point(ex.Position.X + sbHorz.Value, ex.Position.Y + sbVert.Value);
|
||||
|
||||
base.OnClick(e);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
protected override void OnMouseScroll(MouseEventArgs e)
|
||||
{
|
||||
if (!ClientArea.Enabled)
|
||||
return;
|
||||
|
||||
// If current control doesn't scroll, scroll the parent control
|
||||
if (sbVert.Range - sbVert.PageSize < 1)
|
||||
{
|
||||
Control c = this;
|
||||
|
||||
while (c != null)
|
||||
{
|
||||
var p = c.Parent as Container;
|
||||
|
||||
if (p != null && p.Enabled)
|
||||
{
|
||||
p.OnMouseScroll(e);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
c = c.Parent;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.ScrollDirection == MouseScrollDirection.Down)
|
||||
sbVert.ScrollDown(ScrollAlot);
|
||||
else
|
||||
sbVert.ScrollUp(ScrollAlot);
|
||||
|
||||
base.OnMouseScroll(e);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
๏ปฟ////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: ContentReaders.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
|
||||
#if (!XBOX && !XBOX_FAKE)
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework;
|
||||
#endif
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public class LayoutXmlDocument : XmlDocument { }
|
||||
public class SkinXmlDocument : XmlDocument { }
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public class SkinReader : ContentTypeReader<SkinXmlDocument>
|
||||
{
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override SkinXmlDocument Read(ContentReader input, SkinXmlDocument existingInstance)
|
||||
{
|
||||
if (existingInstance == null)
|
||||
{
|
||||
SkinXmlDocument doc = new SkinXmlDocument();
|
||||
doc.LoadXml(input.ReadString());
|
||||
return doc;
|
||||
}
|
||||
else
|
||||
{
|
||||
existingInstance.LoadXml(input.ReadString());
|
||||
}
|
||||
|
||||
return existingInstance;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
public class LayoutReader : ContentTypeReader<LayoutXmlDocument>
|
||||
{
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override LayoutXmlDocument Read(ContentReader input, LayoutXmlDocument existingInstance)
|
||||
{
|
||||
if (existingInstance == null)
|
||||
{
|
||||
LayoutXmlDocument doc = new LayoutXmlDocument();
|
||||
doc.LoadXml(input.ReadString());
|
||||
return doc;
|
||||
}
|
||||
else
|
||||
{
|
||||
existingInstance.LoadXml(input.ReadString());
|
||||
}
|
||||
|
||||
return existingInstance;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
#if (!XBOX && !XBOX_FAKE)
|
||||
|
||||
public class CursorReader : ContentTypeReader<Cursor>
|
||||
{
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override Cursor Read(ContentReader input, Cursor existingInstance)
|
||||
{
|
||||
if (existingInstance == null)
|
||||
{
|
||||
int count = input.ReadInt32();
|
||||
byte[] data = input.ReadBytes(count);
|
||||
|
||||
string path = Path.GetTempFileName();
|
||||
File.WriteAllBytes(path, data);
|
||||
string tPath = Path.GetTempFileName();
|
||||
using(System.Drawing.Icon i = System.Drawing.Icon.ExtractAssociatedIcon(path))
|
||||
{
|
||||
using (System.Drawing.Bitmap b = i.ToBitmap())
|
||||
{
|
||||
|
||||
b.Save(tPath, System.Drawing.Imaging.ImageFormat.Png);
|
||||
b.Dispose();
|
||||
}
|
||||
|
||||
i.Dispose();
|
||||
}
|
||||
//TODO: Replace with xml based solution for getting hotspot and size instead
|
||||
IntPtr handle = NativeMethods.LoadCursor(path);
|
||||
System.Windows.Forms.Cursor c = new System.Windows.Forms.Cursor(handle);
|
||||
Vector2 hs = new Vector2(c.HotSpot.X, c.HotSpot.Y);
|
||||
int w = c.Size.Width;
|
||||
int h = c.Size.Height;
|
||||
c.Dispose();
|
||||
File.Delete(path);
|
||||
|
||||
return new Cursor(tPath, hs, w, h);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
return existingInstance;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@@ -1,575 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: ContextMenu.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
public class ContextMenu: MenuBase
|
||||
{
|
||||
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private long timer = 0;
|
||||
private Control sender = null;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Properties ////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected internal Control Sender { get { return sender; } set { sender = value; } }
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Construstors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public ContextMenu(Manager manager): base(manager)
|
||||
{
|
||||
Visible = false;
|
||||
Detached = true;
|
||||
StayOnBack = true;
|
||||
|
||||
Manager.Input.MouseDown += new MouseEventHandler(Input_MouseDown);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Destructors ///////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Manager.Input.MouseDown -= Input_MouseDown;
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected internal override void InitSkin()
|
||||
{
|
||||
base.InitSkin();
|
||||
Skin = new SkinControl(Manager.Skin.Controls["ContextMenu"]);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime)
|
||||
{
|
||||
base.DrawControl(renderer, rect, gameTime);
|
||||
|
||||
SkinLayer l1 = Skin.Layers["Control"];
|
||||
SkinLayer l2 = Skin.Layers["Selection"];
|
||||
|
||||
int vsize = LineHeight();
|
||||
Color col = Color.White;
|
||||
|
||||
for (int i = 0; i < Items.Count; i++)
|
||||
{
|
||||
int mod = i > 0 ? 2 : 0;
|
||||
int left = rect.Left + l1.ContentMargins.Left + vsize;
|
||||
int h = vsize - mod - (i < (Items.Count - 1) ? 1 : 0);
|
||||
int top = rect.Top + l1.ContentMargins.Top + (i * vsize) + mod;
|
||||
|
||||
|
||||
if (Items[i].Separated && i > 0)
|
||||
{
|
||||
Rectangle r = new Rectangle(left, rect.Top + l1.ContentMargins.Top + (i * vsize), LineWidth() - vsize + 4, 1);
|
||||
renderer.Draw(Manager.Skin.Controls["Control"].Layers[0].Image.Resource, r, l1.Text.Colors.Enabled);
|
||||
}
|
||||
if (ItemIndex != i)
|
||||
{
|
||||
if (Items[i].Enabled)
|
||||
{
|
||||
Rectangle r = new Rectangle(left, top, LineWidth() - vsize, h);
|
||||
renderer.DrawString(this, l1, Items[i].Text, r, false);
|
||||
col = l1.Text.Colors.Enabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
Rectangle r = new Rectangle(left + l1.Text.OffsetX,
|
||||
top + l1.Text.OffsetY,
|
||||
LineWidth() - vsize, h);
|
||||
renderer.DrawString(l1.Text.Font.Resource, Items[i].Text, r, l1.Text.Colors.Disabled, l1.Text.Alignment);
|
||||
col = l1.Text.Colors.Disabled;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Items[i].Enabled)
|
||||
{
|
||||
Rectangle rs = new Rectangle(rect.Left + l1.ContentMargins.Left,
|
||||
top,
|
||||
Width - (l1.ContentMargins.Horizontal - Skin.OriginMargins.Horizontal),
|
||||
h);
|
||||
renderer.DrawLayer(this, l2, rs);
|
||||
|
||||
Rectangle r = new Rectangle(left,
|
||||
top, LineWidth() - vsize, h);
|
||||
|
||||
renderer.DrawString(this, l2, Items[i].Text, r, false);
|
||||
col = l2.Text.Colors.Enabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
Rectangle rs = new Rectangle(rect.Left + l1.ContentMargins.Left,
|
||||
top,
|
||||
Width - (l1.ContentMargins.Horizontal - Skin.OriginMargins.Horizontal),
|
||||
vsize);
|
||||
renderer.DrawLayer(l2, rs, l2.States.Disabled.Color, l2.States.Disabled.Index);
|
||||
|
||||
Rectangle r = new Rectangle(left + l1.Text.OffsetX,
|
||||
top + l1.Text.OffsetY,
|
||||
LineWidth() - vsize, h);
|
||||
renderer.DrawString(l2.Text.Font.Resource, Items[i].Text, r, l2.Text.Colors.Disabled, l2.Text.Alignment);
|
||||
col = l2.Text.Colors.Disabled;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (Items[i].Image != null)
|
||||
{
|
||||
Rectangle r = new Rectangle(rect.Left + l1.ContentMargins.Left + 3,
|
||||
rect.Top + top + 3,
|
||||
LineHeight() - 6,
|
||||
LineHeight() - 6);
|
||||
renderer.Draw(Items[i].Image, r, Color.White);
|
||||
}
|
||||
|
||||
if (Items[i].Items != null && Items[i].Items.Count > 0)
|
||||
{
|
||||
renderer.Draw(Manager.Skin.Images["Shared.ArrowRight"].Resource, rect.Left + LineWidth() - 4, rect.Top + l1.ContentMargins.Top + (i * vsize) + 8, col);
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private int LineHeight()
|
||||
{
|
||||
int h = 0;
|
||||
if (Items.Count > 0)
|
||||
{
|
||||
SkinLayer l = Skin.Layers["Control"];
|
||||
h = (int)l.Text.Font.Resource.LineSpacing + 9;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private int LineWidth()
|
||||
{
|
||||
int w = 0;
|
||||
SkinFont font = Skin.Layers["Control"].Text.Font;
|
||||
if (Items.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < Items.Count; i++)
|
||||
{
|
||||
int wx = (int)font.Resource.MeasureString(Items[i].Text).X + 16;
|
||||
if (wx > w) w = wx;
|
||||
}
|
||||
}
|
||||
|
||||
w += 4 + LineHeight();
|
||||
|
||||
return w;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private void AutoSize()
|
||||
{
|
||||
SkinText font = Skin.Layers["Control"].Text;
|
||||
if (Items != null && Items.Count > 0)
|
||||
{
|
||||
Height = (LineHeight() * Items.Count) + (Skin.Layers["Control"].ContentMargins.Vertical - Skin.OriginMargins.Vertical);
|
||||
Width = LineWidth() + (Skin.Layers["Control"].ContentMargins.Horizontal - Skin.OriginMargins.Horizontal) + font.OffsetX;
|
||||
}
|
||||
else
|
||||
{
|
||||
Height = 16;
|
||||
Width = 16;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private void TrackItem(int x, int y)
|
||||
{
|
||||
if (Items != null && Items.Count > 0)
|
||||
{
|
||||
SkinText font = Skin.Layers["Control"].Text;
|
||||
int h = LineHeight();
|
||||
y -= Skin.Layers["Control"].ContentMargins.Top;
|
||||
int i = (int)((float)y / h);
|
||||
if (i < Items.Count)
|
||||
{
|
||||
if (i != ItemIndex && Items[i].Enabled)
|
||||
{
|
||||
if (ChildMenu != null)
|
||||
{
|
||||
this.HideMenu(false);
|
||||
}
|
||||
|
||||
if (i >= 0 && i != ItemIndex)
|
||||
{
|
||||
Items[i].SelectedInvoke(new EventArgs());
|
||||
}
|
||||
|
||||
Focused = true;
|
||||
ItemIndex = i;
|
||||
timer = (long)TimeSpan.FromTicks(DateTime.Now.Ticks).TotalMilliseconds;
|
||||
}
|
||||
else if (!Items[i].Enabled && ChildMenu == null)
|
||||
{
|
||||
ItemIndex = -1;
|
||||
}
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
TrackItem(e.Position.X, e.Position.Y);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected internal override void Update(GameTime gameTime)
|
||||
{
|
||||
base.Update(gameTime);
|
||||
|
||||
AutoSize();
|
||||
|
||||
long time = (long)TimeSpan.FromTicks(DateTime.Now.Ticks).TotalMilliseconds;
|
||||
|
||||
if (timer != 0 && time - timer >= Manager.MenuDelay && ItemIndex >= 0 && Items[ItemIndex].Items.Count > 0 && ChildMenu == null)
|
||||
{
|
||||
OnClick(new MouseEventArgs(new MouseState(), MouseButton.Left, Point.Zero));
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void OnMouseOut(MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseOut(e);
|
||||
|
||||
if (!CheckArea(e.State.X, e.State.Y) && ChildMenu == null)
|
||||
{
|
||||
ItemIndex = -1;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void OnClick(EventArgs e)
|
||||
{
|
||||
if (sender != null && !(sender is MenuBase)) sender.Focused = true;
|
||||
base.OnClick(e);
|
||||
timer = 0;
|
||||
|
||||
MouseEventArgs ex = (e is MouseEventArgs) ? (MouseEventArgs)e : new MouseEventArgs();
|
||||
|
||||
if (ex.Button == MouseButton.Left || ex.Button == MouseButton.None)
|
||||
{
|
||||
if (ItemIndex >= 0 && Items[ItemIndex].Enabled)
|
||||
{
|
||||
if (ItemIndex >= 0 && Items[ItemIndex].Items != null && Items[ItemIndex].Items.Count > 0)
|
||||
{
|
||||
if (ChildMenu == null)
|
||||
{
|
||||
ChildMenu = new ContextMenu(Manager);
|
||||
(ChildMenu as ContextMenu).RootMenu = this.RootMenu;
|
||||
(ChildMenu as ContextMenu).ParentMenu = this;
|
||||
(ChildMenu as ContextMenu).sender = sender;
|
||||
ChildMenu.Items.AddRange(Items[ItemIndex].Items);
|
||||
(ChildMenu as ContextMenu).AutoSize();
|
||||
}
|
||||
int y = AbsoluteTop + Skin.Layers["Control"].ContentMargins.Top + (ItemIndex * LineHeight());
|
||||
(ChildMenu as ContextMenu).Show(sender, AbsoluteLeft + Width - 1, y);
|
||||
if (ex.Button == MouseButton.None) (ChildMenu as ContextMenu).ItemIndex = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ItemIndex >= 0)
|
||||
{
|
||||
Items[ItemIndex].ClickInvoke(ex);
|
||||
}
|
||||
if (RootMenu is ContextMenu) (RootMenu as ContextMenu).HideMenu(true);
|
||||
else if (RootMenu is MainMenu)
|
||||
{
|
||||
(RootMenu as MainMenu).HideMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void OnKeyPress(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyPress(e);
|
||||
|
||||
timer = 0;
|
||||
|
||||
if (e.Key == Keys.Down || (e.Key == Keys.Tab && !e.Shift))
|
||||
{
|
||||
e.Handled = true;
|
||||
ItemIndex += 1;
|
||||
}
|
||||
|
||||
if (e.Key == Keys.Up || (e.Key == Keys.Tab && e.Shift))
|
||||
{
|
||||
e.Handled = true;
|
||||
ItemIndex -=1;
|
||||
}
|
||||
|
||||
if (ItemIndex > Items.Count - 1) ItemIndex = 0;
|
||||
if (ItemIndex < 0) ItemIndex = Items.Count - 1;
|
||||
|
||||
if (e.Key == Keys.Right && Items[ItemIndex].Items.Count > 0)
|
||||
{
|
||||
e.Handled = true;
|
||||
OnClick(new MouseEventArgs(new MouseState(), MouseButton.None, Point.Zero));
|
||||
}
|
||||
if (e.Key == Keys.Left)
|
||||
{
|
||||
e.Handled = true;
|
||||
if (ParentMenu != null && ParentMenu is ContextMenu)
|
||||
{
|
||||
(ParentMenu as ContextMenu).Focused = true;
|
||||
(ParentMenu as ContextMenu).HideMenu(false);
|
||||
}
|
||||
}
|
||||
if (e.Key == Keys.Escape)
|
||||
{
|
||||
e.Handled = true;
|
||||
if (ParentMenu != null) ParentMenu.Focused = true;
|
||||
HideMenu(true);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void OnGamePadPress(GamePadEventArgs e)
|
||||
{
|
||||
timer = 0;
|
||||
|
||||
if (e.Button == GamePadButton.None) return;
|
||||
|
||||
if (e.Button == GamePadActions.Down || e.Button == GamePadActions.NextControl)
|
||||
{
|
||||
e.Handled = true;
|
||||
ItemIndex += 1;
|
||||
}
|
||||
else if (e.Button == GamePadActions.Up || e.Button == GamePadActions.PrevControl)
|
||||
{
|
||||
e.Handled = true;
|
||||
ItemIndex -= 1;
|
||||
}
|
||||
|
||||
if (ItemIndex > Items.Count - 1) ItemIndex = 0;
|
||||
if (ItemIndex < 0) ItemIndex = Items.Count - 1;
|
||||
|
||||
if (e.Button == GamePadActions.Right && Items[ItemIndex].Items.Count > 0)
|
||||
{
|
||||
e.Handled = true;
|
||||
OnClick(new MouseEventArgs(new MouseState(), MouseButton.None, Point.Zero));
|
||||
}
|
||||
if (e.Button == GamePadActions.Left)
|
||||
{
|
||||
e.Handled = true;
|
||||
if (ParentMenu != null && ParentMenu is ContextMenu)
|
||||
{
|
||||
(ParentMenu as ContextMenu).Focused = true;
|
||||
(ParentMenu as ContextMenu).HideMenu(false);
|
||||
}
|
||||
}
|
||||
|
||||
base.OnGamePadPress(e);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual void HideMenu(bool hideCurrent)
|
||||
{
|
||||
if (hideCurrent)
|
||||
{
|
||||
Visible = false;
|
||||
ItemIndex = -1;
|
||||
}
|
||||
if (ChildMenu != null)
|
||||
{
|
||||
(ChildMenu as ContextMenu).HideMenu(true);
|
||||
ChildMenu.Dispose();
|
||||
ChildMenu = null;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override void Show()
|
||||
{
|
||||
Show(null, Left, Top);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual void Show(Control sender, int x, int y)
|
||||
{
|
||||
AutoSize();
|
||||
base.Show();
|
||||
if (!Initialized) Init();
|
||||
if (sender != null && sender.Root != null && sender.Root is Container)
|
||||
{
|
||||
(sender.Root as Container).Add(this, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Manager.Add(this);
|
||||
}
|
||||
|
||||
this.sender = sender;
|
||||
|
||||
if (sender != null && sender.Root != null && sender.Root is Container)
|
||||
{
|
||||
Left = x - Root.AbsoluteLeft;
|
||||
Top = y - Root.AbsoluteTop;
|
||||
}
|
||||
else
|
||||
{
|
||||
Left = x;
|
||||
Top = y;
|
||||
}
|
||||
|
||||
if (AbsoluteLeft + Width > Manager.TargetWidth)
|
||||
{
|
||||
Left = Left - Width;
|
||||
if (ParentMenu != null && ParentMenu is ContextMenu)
|
||||
{
|
||||
Left = Left - ParentMenu.Width + 2;
|
||||
}
|
||||
else if (ParentMenu != null)
|
||||
{
|
||||
Left = Manager.TargetWidth - (Parent != null ? Parent.AbsoluteLeft : 0) - Width - 2;
|
||||
}
|
||||
}
|
||||
if (AbsoluteTop + Height > Manager.TargetHeight)
|
||||
{
|
||||
Top = Top - Height;
|
||||
if (ParentMenu != null && ParentMenu is ContextMenu)
|
||||
{
|
||||
Top = Top + LineHeight();
|
||||
}
|
||||
else if (ParentMenu != null)
|
||||
{
|
||||
Top = ParentMenu.Top - Height - 1;
|
||||
}
|
||||
}
|
||||
|
||||
Focused = true;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private void Input_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
if ((RootMenu is ContextMenu) && !(RootMenu as ContextMenu).CheckArea(e.Position.X, e.Position.Y) && Visible)
|
||||
{
|
||||
HideMenu(true);
|
||||
}
|
||||
else if ((RootMenu is MainMenu) && RootMenu.ChildMenu != null && !(RootMenu.ChildMenu as ContextMenu).CheckArea(e.Position.X, e.Position.Y) && Visible)
|
||||
{
|
||||
(RootMenu as MainMenu).HideMenu();
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private bool CheckArea(int x, int y)
|
||||
{
|
||||
if (Visible)
|
||||
{
|
||||
if (x <= AbsoluteLeft ||
|
||||
x >= AbsoluteLeft + Width ||
|
||||
y <= AbsoluteTop ||
|
||||
y >= AbsoluteTop + Height)
|
||||
{
|
||||
bool ret = false;
|
||||
if (ChildMenu != null)
|
||||
{
|
||||
ret = (ChildMenu as ContextMenu).CheckArea(x, y);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
3045
Neoforce/Control.cs
3045
Neoforce/Control.cs
File diff suppressed because it is too large
Load Diff
@@ -1,56 +0,0 @@
|
||||
๏ปฟusing Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a basic Software cursor
|
||||
/// </summary>
|
||||
public class Cursor
|
||||
{
|
||||
private Texture2D cursorTexture;
|
||||
|
||||
public Texture2D CursorTexture
|
||||
{
|
||||
get { return cursorTexture;}
|
||||
set { cursorTexture = value; }
|
||||
}
|
||||
|
||||
internal string cursorPath;
|
||||
|
||||
private Vector2 hotspot;
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
public int Height
|
||||
{
|
||||
get { return height; }
|
||||
set { height = value; }
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get { return width; }
|
||||
set { width = value; }
|
||||
}
|
||||
|
||||
public Vector2 HotSpot
|
||||
{
|
||||
get { return hotspot; }
|
||||
set { hotspot = value; }
|
||||
}
|
||||
|
||||
public Cursor(string path, Vector2 hotspot, int width, int height)
|
||||
{
|
||||
this.cursorPath = path;
|
||||
this.hotspot = hotspot;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: Delegates.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
#region //// Delegates /////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public delegate void DeviceEventHandler(DeviceEventArgs e);
|
||||
public delegate void SkinEventHandler(EventArgs e);
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public delegate void EventHandler(object sender, EventArgs e);
|
||||
public delegate void MouseEventHandler(object sender, MouseEventArgs e);
|
||||
public delegate void KeyEventHandler(object sender, KeyEventArgs e);
|
||||
public delegate void GamePadEventHandler(object sender, GamePadEventArgs e);
|
||||
public delegate void DrawEventHandler(object sender, DrawEventArgs e);
|
||||
public delegate void MoveEventHandler(object sender, MoveEventArgs e);
|
||||
public delegate void ResizeEventHandler(object sender, ResizeEventArgs e);
|
||||
public delegate void WindowClosingEventHandler(object sender, WindowClosingEventArgs e);
|
||||
public delegate void WindowClosedEventHandler(object sender, WindowClosedEventArgs e);
|
||||
public delegate void ConsoleMessageEventHandler(object sender, ConsoleMessageEventArgs e);
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Central //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: Dialog.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
public class Dialog: Window
|
||||
{
|
||||
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private Panel pnlTop = null;
|
||||
private Label lblCapt = null;
|
||||
private Label lblDesc = null;
|
||||
private Panel pnlBottom = null;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Properties ////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public Panel TopPanel { get { return pnlTop; } }
|
||||
public Panel BottomPanel { get { return pnlBottom; } }
|
||||
public Label Caption { get { return lblCapt; } }
|
||||
public Label Description { get { return lblDesc; } }
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Events ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Construstors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public Dialog(Manager manager): base(manager)
|
||||
{
|
||||
pnlTop = new Panel(manager);
|
||||
pnlTop.Anchor = Anchors.Left | Anchors.Top | Anchors.Right;
|
||||
pnlTop.Init();
|
||||
pnlTop.Parent = this;
|
||||
pnlTop.Width = ClientWidth;
|
||||
pnlTop.Height = 64;
|
||||
pnlTop.BevelBorder = BevelBorder.Bottom;
|
||||
|
||||
lblCapt = new Label(manager);
|
||||
lblCapt.Init();
|
||||
lblCapt.Parent = pnlTop;
|
||||
lblCapt.Width = lblCapt.Parent.ClientWidth - 16;
|
||||
lblCapt.Text = "Caption";
|
||||
lblCapt.Left = 8;
|
||||
lblCapt.Top = 8;
|
||||
lblCapt.Alignment = Alignment.TopLeft;
|
||||
lblCapt.Anchor = Anchors.Left | Anchors.Top | Anchors.Right;
|
||||
|
||||
lblDesc = new Label(manager);
|
||||
lblDesc.Init();
|
||||
lblDesc.Parent = pnlTop;
|
||||
lblDesc.Width = lblDesc.Parent.ClientWidth - 16;
|
||||
lblDesc.Left = 8;
|
||||
lblDesc.Text = "Description text.";
|
||||
lblDesc.Alignment = Alignment.TopLeft;
|
||||
lblDesc.Anchor = Anchors.Left | Anchors.Top | Anchors.Right;
|
||||
|
||||
pnlBottom = new Panel(manager);
|
||||
pnlBottom.Init();
|
||||
pnlBottom.Parent = this;
|
||||
pnlBottom.Width = ClientWidth;
|
||||
pnlBottom.Height = 24 + 16;
|
||||
pnlBottom.Top = ClientHeight - pnlBottom.Height;
|
||||
pnlBottom.BevelBorder = BevelBorder.Top;
|
||||
pnlBottom.Anchor = Anchors.Left | Anchors.Bottom | Anchors.Right;
|
||||
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
SkinLayer lc = new SkinLayer(lblCapt.Skin.Layers[0]);
|
||||
lc.Text.Font.Resource = Manager.Skin.Fonts[Manager.Skin.Controls["Dialog"].Layers["TopPanel"].Attributes["CaptFont"].Value].Resource;
|
||||
lc.Text.Colors.Enabled = Utilities.ParseColor(Manager.Skin.Controls["Dialog"].Layers["TopPanel"].Attributes["CaptFontColor"].Value);
|
||||
|
||||
SkinLayer ld = new SkinLayer(lblDesc.Skin.Layers[0]);
|
||||
ld.Text.Font.Resource = Manager.Skin.Fonts[Manager.Skin.Controls["Dialog"].Layers["TopPanel"].Attributes["DescFont"].Value].Resource;
|
||||
ld.Text.Colors.Enabled = Utilities.ParseColor(Manager.Skin.Controls["Dialog"].Layers["TopPanel"].Attributes["DescFontColor"].Value);
|
||||
|
||||
pnlTop.Color = Utilities.ParseColor(Manager.Skin.Controls["Dialog"].Layers["TopPanel"].Attributes["Color"].Value);
|
||||
pnlTop.BevelMargin = int.Parse(Manager.Skin.Controls["Dialog"].Layers["TopPanel"].Attributes["BevelMargin"].Value);
|
||||
pnlTop.BevelStyle = Utilities.ParseBevelStyle(Manager.Skin.Controls["Dialog"].Layers["TopPanel"].Attributes["BevelStyle"].Value);
|
||||
|
||||
lblCapt.Skin = new SkinControl(lblCapt.Skin);
|
||||
lblCapt.Skin.Layers[0] = lc;
|
||||
lblCapt.Height = Manager.Skin.Fonts[Manager.Skin.Controls["Dialog"].Layers["TopPanel"].Attributes["CaptFont"].Value].Height;
|
||||
|
||||
lblDesc.Skin = new SkinControl(lblDesc.Skin);
|
||||
lblDesc.Skin.Layers[0] = ld;
|
||||
lblDesc.Height = Manager.Skin.Fonts[Manager.Skin.Controls["Dialog"].Layers["TopPanel"].Attributes["DescFont"].Value].Height;
|
||||
lblDesc.Top = lblCapt.Top + lblCapt.Height + 4;
|
||||
lblDesc.Height = lblDesc.Parent.ClientHeight - lblDesc.Top - 8;
|
||||
|
||||
pnlBottom.Color = Utilities.ParseColor(Manager.Skin.Controls["Dialog"].Layers["BottomPanel"].Attributes["Color"].Value);
|
||||
pnlBottom.BevelMargin = int.Parse(Manager.Skin.Controls["Dialog"].Layers["BottomPanel"].Attributes["BevelMargin"].Value);
|
||||
pnlBottom.BevelStyle = Utilities.ParseBevelStyle(Manager.Skin.Controls["Dialog"].Layers["BottomPanel"].Attributes["BevelStyle"].Value);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: Disposable.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
using System;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
public abstract class Disposable: Unknown, IDisposable
|
||||
{
|
||||
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private static int count = 0;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Properties ////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public static int Count { get { return count; } }
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Constructors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected Disposable()
|
||||
{
|
||||
count += 1;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Destructors ///////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
~Disposable()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
count -= 1;
|
||||
}
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,427 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: EventArgs.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
#region //// Classes ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public class EventArgs: System.EventArgs
|
||||
{
|
||||
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public bool Handled = false;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Consructors ///////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public EventArgs()
|
||||
{
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public class KeyEventArgs: EventArgs
|
||||
{
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public Keys Key = Keys.None;
|
||||
public bool Control = false;
|
||||
public bool Shift = false;
|
||||
public bool Alt = false;
|
||||
public bool Caps = false;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Constructors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public KeyEventArgs()
|
||||
{
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public KeyEventArgs(Keys key)
|
||||
{
|
||||
Key = key;
|
||||
Control = false;
|
||||
Shift = false;
|
||||
Alt = false;
|
||||
Caps = false;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public KeyEventArgs(Keys key, bool control, bool shift, bool alt, bool caps)
|
||||
{
|
||||
Key = key;
|
||||
Control = control;
|
||||
Shift = shift;
|
||||
Alt = alt;
|
||||
Caps = caps;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public class MouseEventArgs: EventArgs
|
||||
{
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public MouseState State = new MouseState();
|
||||
public MouseButton Button = MouseButton.None;
|
||||
public Point Position = new Point(0, 0);
|
||||
public Point Difference = new Point(0, 0);
|
||||
/// <summary>
|
||||
/// Mouse scroll direction
|
||||
/// </summary>
|
||||
public MouseScrollDirection ScrollDirection = MouseScrollDirection.None;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Constructors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public MouseEventArgs()
|
||||
{
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public MouseEventArgs(MouseState state, MouseButton button, Point position)
|
||||
{
|
||||
State = state;
|
||||
Button = button;
|
||||
Position = position;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new initialized instace of the MouseEventArgs class.
|
||||
/// <param name="state">Mouse state at the time of the event.</param>
|
||||
/// <param name="button">Mouse button state at the time of the event.</param>
|
||||
/// <param name="position">Mosue cursor position at the time of the event.</param>
|
||||
/// <param name="scrollDirection">Mouse scroll direction at the time of the event.</param>
|
||||
public MouseEventArgs(MouseState state, MouseButton button, Point position, MouseScrollDirection scrollDirection)
|
||||
: this(state, button, position)
|
||||
{
|
||||
ScrollDirection = scrollDirection;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public MouseEventArgs(MouseEventArgs e)
|
||||
: this(e.State, e.Button, e.Position)
|
||||
{
|
||||
Difference = e.Difference;
|
||||
ScrollDirection = e.ScrollDirection;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public class GamePadEventArgs : EventArgs
|
||||
{
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public PlayerIndex PlayerIndex = PlayerIndex.One;
|
||||
public GamePadState State = new GamePadState();
|
||||
public GamePadButton Button = GamePadButton.None;
|
||||
public GamePadVectors Vectors;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Constructors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
public GamePadEventArgs()
|
||||
{
|
||||
}*/
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public GamePadEventArgs(PlayerIndex playerIndex)
|
||||
{
|
||||
PlayerIndex = playerIndex;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public GamePadEventArgs(PlayerIndex playerIndex, GamePadButton button)
|
||||
{
|
||||
PlayerIndex = playerIndex;
|
||||
Button = button;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public class DrawEventArgs: EventArgs
|
||||
{
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public Renderer Renderer = null;
|
||||
public Rectangle Rectangle = Rectangle.Empty;
|
||||
public GameTime GameTime = null;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Constructors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public DrawEventArgs()
|
||||
{
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public DrawEventArgs(Renderer renderer, Rectangle rectangle, GameTime gameTime)
|
||||
{
|
||||
Renderer = renderer;
|
||||
Rectangle = rectangle;
|
||||
GameTime = gameTime;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public class ResizeEventArgs: EventArgs
|
||||
{
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public int Width = 0;
|
||||
public int Height = 0;
|
||||
public int OldWidth = 0;
|
||||
public int OldHeight = 0;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Constructors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public ResizeEventArgs()
|
||||
{
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public ResizeEventArgs(int width, int height, int oldWidth, int oldHeight)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
OldWidth = oldWidth;
|
||||
OldHeight = oldHeight;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public class MoveEventArgs: EventArgs
|
||||
{
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public int Left = 0;
|
||||
public int Top = 0;
|
||||
public int OldLeft = 0;
|
||||
public int OldTop = 0;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Constructors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public MoveEventArgs()
|
||||
{
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public MoveEventArgs(int left, int top, int oldLeft, int oldTop)
|
||||
{
|
||||
Left = left;
|
||||
Top = top;
|
||||
OldLeft = oldLeft;
|
||||
OldTop = oldTop;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public class DeviceEventArgs: EventArgs
|
||||
{
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public PreparingDeviceSettingsEventArgs DeviceSettings = null;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Constructors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public DeviceEventArgs()
|
||||
{
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public DeviceEventArgs(PreparingDeviceSettingsEventArgs deviceSettings)
|
||||
{
|
||||
DeviceSettings = deviceSettings;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public class WindowClosingEventArgs: EventArgs
|
||||
{
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public bool Cancel = false;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Consructors ///////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public WindowClosingEventArgs()
|
||||
{
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public class WindowClosedEventArgs: EventArgs
|
||||
{
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public bool Dispose = false;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Consructors ///////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public WindowClosedEventArgs()
|
||||
{
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public class ConsoleMessageEventArgs : EventArgs
|
||||
{
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public ConsoleMessage Message;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Consructors ///////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public ConsoleMessageEventArgs()
|
||||
{
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public ConsoleMessageEventArgs(ConsoleMessage message)
|
||||
{
|
||||
Message = message;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
๏ปฟ////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: EventedList.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
public class EventedList<T>: List<T>
|
||||
{
|
||||
|
||||
#region //// Events ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public event EventHandler ItemAdded;
|
||||
public event EventHandler ItemRemoved;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Constructors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public EventedList(): base() {}
|
||||
public EventedList(int capacity): base(capacity) {}
|
||||
public EventedList(IEnumerable<T> collection): base(collection) {}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public new void Add(T item)
|
||||
{
|
||||
int c = this.Count;
|
||||
base.Add(item);
|
||||
if (ItemAdded != null && c != this.Count) ItemAdded.Invoke(this, new EventArgs());
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public new void Remove(T obj)
|
||||
{
|
||||
int c = this.Count;
|
||||
base.Remove(obj);
|
||||
if (ItemRemoved != null && c != this.Count) ItemRemoved.Invoke(this, new EventArgs());
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public new void Clear()
|
||||
{
|
||||
int c = this.Count;
|
||||
base.Clear();
|
||||
if (ItemRemoved != null && c != this.Count) ItemRemoved.Invoke(this, new EventArgs());
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public new void AddRange(IEnumerable<T> collection)
|
||||
{
|
||||
int c = this.Count;
|
||||
base.AddRange(collection);
|
||||
if (ItemAdded != null && c != this.Count) ItemAdded.Invoke(this, new EventArgs());
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public new void Insert(int index, T item)
|
||||
{
|
||||
int c = this.Count;
|
||||
base.Insert(index, item);
|
||||
if (ItemAdded != null && c != this.Count) ItemAdded.Invoke(this, new EventArgs());
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public new void InsertRange(int index, IEnumerable<T> collection)
|
||||
{
|
||||
int c = this.Count;
|
||||
base.InsertRange(index, collection);
|
||||
if (ItemAdded != null && c != this.Count) ItemAdded.Invoke(this, new EventArgs());
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public new int RemoveAll(Predicate<T> match)
|
||||
{
|
||||
int c = this.Count;
|
||||
int ret = base.RemoveAll(match);
|
||||
if (ItemRemoved != null && c != this.Count) ItemRemoved.Invoke(this, new EventArgs());
|
||||
return ret;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public new void RemoveAt(int index)
|
||||
{
|
||||
int c = this.Count;
|
||||
base.RemoveAt(index);
|
||||
if (ItemRemoved != null && c != this.Count) ItemRemoved.Invoke(this, new EventArgs());
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public new void RemoveRange(int index, int count)
|
||||
{
|
||||
int c = this.Count;
|
||||
base.RemoveRange(index, count);
|
||||
if (ItemRemoved != null && c != this.Count) ItemRemoved.Invoke(this, new EventArgs());
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Central //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: ExitDialog.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
public class ExitDialog: Dialog
|
||||
{
|
||||
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public Button btnYes;
|
||||
public Button btnNo;
|
||||
private Label lblMessage;
|
||||
private ImageBox imgIcon;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Properties ////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Events ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Construstors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public ExitDialog(Manager manager): base(manager)
|
||||
{
|
||||
string msg = "Do you really want to exit " + Manager.Game.Window.Title + "?";
|
||||
ClientWidth = (int)Manager.Skin.Controls["Label"].Layers[0].Text.Font.Resource.MeasureString(msg).X + 48 + 16 + 16 + 16;
|
||||
ClientHeight = 120;
|
||||
TopPanel.Visible = false;
|
||||
IconVisible = true;
|
||||
Resizable = false;
|
||||
Text = Manager.Game.Window.Title;
|
||||
Center();
|
||||
|
||||
imgIcon = new ImageBox(Manager);
|
||||
imgIcon.Init();
|
||||
imgIcon.Image = Manager.Skin.Images["Icon.Question"].Resource;
|
||||
imgIcon.Left = 16;
|
||||
imgIcon.Top = 16;
|
||||
imgIcon.Width = 48;
|
||||
imgIcon.Height = 48;
|
||||
imgIcon.SizeMode = SizeMode.Stretched;
|
||||
|
||||
lblMessage = new Label(Manager);
|
||||
lblMessage.Init();
|
||||
|
||||
lblMessage.Left = 80;
|
||||
lblMessage.Top = 16;
|
||||
lblMessage.Width = ClientWidth - lblMessage.Left;
|
||||
lblMessage.Height = 48;
|
||||
lblMessage.Alignment = Alignment.TopLeft;
|
||||
lblMessage.Text = msg;
|
||||
|
||||
btnYes = new Button(Manager);
|
||||
btnYes.Init();
|
||||
btnYes.Left = (BottomPanel.ClientWidth / 2) - btnYes.Width - 4;
|
||||
btnYes.Top = 8;
|
||||
btnYes.Text = "Yes";
|
||||
btnYes.ModalResult = ModalResult.Yes;
|
||||
|
||||
btnNo = new Button(Manager);
|
||||
btnNo.Init();
|
||||
btnNo.Left = (BottomPanel.ClientWidth / 2) + 4;
|
||||
btnNo.Top = 8;
|
||||
btnNo.Text = "No";
|
||||
btnNo.ModalResult = ModalResult.No;
|
||||
|
||||
Add(imgIcon);
|
||||
Add(lblMessage);
|
||||
BottomPanel.Add(btnYes);
|
||||
BottomPanel.Add(btnNo);
|
||||
|
||||
DefaultControl = btnNo;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
84
Neoforce/External/Zip/Crc32.cs
vendored
84
Neoforce/External/Zip/Crc32.cs
vendored
@@ -1,84 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace TomShane.Neoforce.External.Zip
|
||||
{
|
||||
internal class CRC32
|
||||
{
|
||||
private UInt32[] crc32Table;
|
||||
private const int BUFFER_SIZE = 8192;
|
||||
|
||||
private Int32 _TotalBytesRead= 0;
|
||||
public Int32 TotalBytesRead {
|
||||
get {
|
||||
return _TotalBytesRead;
|
||||
}
|
||||
}
|
||||
|
||||
public UInt32 GetCrc32(System.IO.Stream input)
|
||||
{
|
||||
return GetCrc32AndCopy(input, null) ;
|
||||
}
|
||||
|
||||
public UInt32 GetCrc32AndCopy(System.IO.Stream input, System.IO.Stream output)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
UInt32 crc32Result;
|
||||
crc32Result = 0xFFFFFFFF;
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
int readSize = BUFFER_SIZE;
|
||||
|
||||
_TotalBytesRead= 0;
|
||||
int count = input.Read(buffer, 0, readSize);
|
||||
if (output != null) output.Write(buffer,0,count);
|
||||
_TotalBytesRead += count;
|
||||
while (count > 0)
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
crc32Result = ((crc32Result) >> 8) ^ crc32Table[(buffer[i]) ^ ((crc32Result) & 0x000000FF)];
|
||||
}
|
||||
count = input.Read(buffer, 0, readSize);
|
||||
if (output != null) output.Write(buffer,0,count);
|
||||
_TotalBytesRead += count;
|
||||
|
||||
}
|
||||
|
||||
return ~crc32Result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public CRC32()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
// This is the official polynomial used by CRC32 in PKZip.
|
||||
// Often the polynomial is shown reversed as 0x04C11DB7.
|
||||
UInt32 dwPolynomial = 0xEDB88320;
|
||||
UInt32 i, j;
|
||||
|
||||
crc32Table = new UInt32[256];
|
||||
|
||||
UInt32 dwCrc;
|
||||
for(i = 0; i < 256; i++)
|
||||
{
|
||||
dwCrc = i;
|
||||
for(j = 8; j > 0; j--)
|
||||
{
|
||||
if ((dwCrc & 1)==1)
|
||||
{
|
||||
dwCrc = (dwCrc >> 1) ^ dwPolynomial;
|
||||
}
|
||||
else
|
||||
{
|
||||
dwCrc >>= 1;
|
||||
}
|
||||
}
|
||||
crc32Table[i] = dwCrc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
112
Neoforce/External/Zip/Shared.cs
vendored
112
Neoforce/External/Zip/Shared.cs
vendored
@@ -1,112 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace TomShane.Neoforce.External.Zip
|
||||
{
|
||||
|
||||
internal class Shared
|
||||
{
|
||||
protected internal static string StringFromBuffer(byte[] buf, int start, int maxlength)
|
||||
{
|
||||
int i;
|
||||
char[] c = new char[maxlength];
|
||||
for (i = 0; (i < maxlength) && (i < buf.Length) && (buf[i] != 0); i++)
|
||||
{
|
||||
c[i] = (char)buf[i]; // System.BitConverter.ToChar(buf, start+i*2);
|
||||
}
|
||||
string s = new System.String(c, 0, i);
|
||||
return s;
|
||||
}
|
||||
|
||||
protected internal static int ReadSignature(System.IO.Stream s)
|
||||
{
|
||||
int n = 0;
|
||||
byte[] sig = new byte[4];
|
||||
n = s.Read(sig, 0, sig.Length);
|
||||
if (n != sig.Length) throw new Exception("Could not read signature - no data!");
|
||||
int signature = (((sig[3] * 256 + sig[2]) * 256) + sig[1]) * 256 + sig[0];
|
||||
return signature;
|
||||
}
|
||||
|
||||
protected internal static long FindSignature(System.IO.Stream s, int SignatureToFind)
|
||||
{
|
||||
long startingPosition = s.Position;
|
||||
|
||||
int BATCH_SIZE = 1024;
|
||||
byte[] targetBytes = new byte[4];
|
||||
targetBytes[0] = (byte) (SignatureToFind >> 24);
|
||||
targetBytes[1] = (byte) ((SignatureToFind & 0x00FF0000) >> 16);
|
||||
targetBytes[2] = (byte) ((SignatureToFind & 0x0000FF00) >> 8);
|
||||
targetBytes[3] = (byte) (SignatureToFind & 0x000000FF);
|
||||
byte[] batch = new byte[BATCH_SIZE];
|
||||
int n = 0;
|
||||
bool success = false;
|
||||
do
|
||||
{
|
||||
n = s.Read(batch, 0, batch.Length);
|
||||
if (n != 0)
|
||||
{
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (batch[i] == targetBytes[3])
|
||||
{
|
||||
s.Seek(i - n, System.IO.SeekOrigin.Current);
|
||||
int sig = ReadSignature(s);
|
||||
success = (sig == SignatureToFind);
|
||||
if (!success) s.Seek(-3, System.IO.SeekOrigin.Current);
|
||||
break; // out of for loop
|
||||
}
|
||||
}
|
||||
}
|
||||
else break;
|
||||
if (success) break;
|
||||
} while (true);
|
||||
if (!success)
|
||||
{
|
||||
s.Seek(startingPosition, System.IO.SeekOrigin.Begin);
|
||||
return -1; // or throw?
|
||||
}
|
||||
|
||||
// subtract 4 for the signature.
|
||||
long bytesRead = (s.Position - startingPosition) - 4 ;
|
||||
// number of bytes read, should be the same as compressed size of file
|
||||
return bytesRead;
|
||||
}
|
||||
protected internal static DateTime PackedToDateTime(Int32 packedDateTime)
|
||||
{
|
||||
Int16 packedTime = (Int16)(packedDateTime & 0x0000ffff);
|
||||
Int16 packedDate = (Int16)((packedDateTime & 0xffff0000) >> 16);
|
||||
|
||||
int year = 1980 + ((packedDate & 0xFE00) >> 9);
|
||||
int month = (packedDate & 0x01E0) >> 5;
|
||||
int day = packedDate & 0x001F;
|
||||
|
||||
|
||||
int hour = (packedTime & 0xF800) >> 11;
|
||||
int minute = (packedTime & 0x07E0) >> 5;
|
||||
int second = packedTime & 0x001F;
|
||||
|
||||
DateTime d = System.DateTime.Now;
|
||||
try { d = new System.DateTime(year, month, day, hour, minute, second, 0); }
|
||||
catch
|
||||
{
|
||||
Console.Write("\nInvalid date/time?:\nyear: {0} ", year);
|
||||
Console.Write("month: {0} ", month);
|
||||
Console.WriteLine("day: {0} ", day);
|
||||
Console.WriteLine("HH:MM:SS= {0}:{1}:{2}", hour, minute, second);
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
protected internal static Int32 DateTimeToPacked(DateTime time)
|
||||
{
|
||||
UInt16 packedDate = (UInt16)((time.Day & 0x0000001F) | ((time.Month << 5) & 0x000001E0) | (((time.Year - 1980) << 9) & 0x0000FE00));
|
||||
UInt16 packedTime = (UInt16)((time.Second & 0x0000001F) | ((time.Minute << 5) & 0x000007E0) | ((time.Hour << 11) & 0x0000F800));
|
||||
return (Int32)(((UInt32)(packedDate << 16)) | packedTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
149
Neoforce/External/Zip/ZipDirEntry.cs
vendored
149
Neoforce/External/Zip/ZipDirEntry.cs
vendored
@@ -1,149 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace TomShane.Neoforce.External.Zip
|
||||
{
|
||||
|
||||
|
||||
internal class ZipDirEntry
|
||||
{
|
||||
|
||||
internal const int ZipDirEntrySignature = 0x02014b50;
|
||||
|
||||
private bool _Debug = false;
|
||||
|
||||
private ZipDirEntry() { }
|
||||
|
||||
private DateTime _LastModified;
|
||||
public DateTime LastModified
|
||||
{
|
||||
get { return _LastModified; }
|
||||
}
|
||||
|
||||
private string _FileName;
|
||||
public string FileName
|
||||
{
|
||||
get { return _FileName; }
|
||||
}
|
||||
|
||||
private string _Comment;
|
||||
public string Comment
|
||||
{
|
||||
get { return _Comment; }
|
||||
}
|
||||
|
||||
private Int16 _VersionMadeBy;
|
||||
public Int16 VersionMadeBy
|
||||
{
|
||||
get { return _VersionMadeBy; }
|
||||
}
|
||||
|
||||
private Int16 _VersionNeeded;
|
||||
public Int16 VersionNeeded
|
||||
{
|
||||
get { return _VersionNeeded; }
|
||||
}
|
||||
|
||||
private Int16 _CompressionMethod;
|
||||
public Int16 CompressionMethod
|
||||
{
|
||||
get { return _CompressionMethod; }
|
||||
}
|
||||
|
||||
private Int32 _CompressedSize;
|
||||
public Int32 CompressedSize
|
||||
{
|
||||
get { return _CompressedSize; }
|
||||
}
|
||||
|
||||
private Int32 _UncompressedSize;
|
||||
public Int32 UncompressedSize
|
||||
{
|
||||
get { return _UncompressedSize; }
|
||||
}
|
||||
|
||||
public Double CompressionRatio
|
||||
{
|
||||
get
|
||||
{
|
||||
return 100 * (1.0 - (1.0 * CompressedSize) / (1.0 * UncompressedSize));
|
||||
}
|
||||
}
|
||||
|
||||
private Int16 _BitField;
|
||||
private Int32 _LastModDateTime;
|
||||
|
||||
private Int32 _Crc32;
|
||||
private byte[] _Extra;
|
||||
|
||||
internal ZipDirEntry(ZipEntry ze) { }
|
||||
|
||||
|
||||
internal static ZipDirEntry Read(System.IO.Stream s)
|
||||
{
|
||||
return Read(s, false);
|
||||
}
|
||||
|
||||
|
||||
internal static ZipDirEntry Read(System.IO.Stream s, bool TurnOnDebug)
|
||||
{
|
||||
|
||||
int signature = TomShane.Neoforce.External.Zip.Shared.ReadSignature(s);
|
||||
// return null if this is not a local file header signature
|
||||
if (SignatureIsNotValid(signature))
|
||||
{
|
||||
s.Seek(-4, System.IO.SeekOrigin.Current);
|
||||
if (TurnOnDebug) System.Console.WriteLine(" ZipDirEntry::Read(): Bad signature ({0:X8}) at position {1}", signature, s.Position);
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] block = new byte[42];
|
||||
int n = s.Read(block, 0, block.Length);
|
||||
if (n != block.Length) return null;
|
||||
|
||||
int i = 0;
|
||||
ZipDirEntry zde = new ZipDirEntry();
|
||||
|
||||
zde._Debug = TurnOnDebug;
|
||||
zde._VersionMadeBy = (short)(block[i++] + block[i++] * 256);
|
||||
zde._VersionNeeded = (short)(block[i++] + block[i++] * 256);
|
||||
zde._BitField = (short)(block[i++] + block[i++] * 256);
|
||||
zde._CompressionMethod = (short)(block[i++] + block[i++] * 256);
|
||||
zde._LastModDateTime = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
|
||||
zde._Crc32 = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
|
||||
zde._CompressedSize = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
|
||||
zde._UncompressedSize = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
|
||||
|
||||
zde._LastModified = TomShane.Neoforce.External.Zip.Shared.PackedToDateTime(zde._LastModDateTime);
|
||||
|
||||
Int16 filenameLength = (short)(block[i++] + block[i++] * 256);
|
||||
Int16 extraFieldLength = (short)(block[i++] + block[i++] * 256);
|
||||
Int16 commentLength = (short)(block[i++] + block[i++] * 256);
|
||||
Int16 diskNumber = (short)(block[i++] + block[i++] * 256);
|
||||
Int16 internalFileAttrs = (short)(block[i++] + block[i++] * 256);
|
||||
Int32 externalFileAttrs = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
|
||||
Int32 Offset = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
|
||||
|
||||
block = new byte[filenameLength];
|
||||
n = s.Read(block, 0, block.Length);
|
||||
zde._FileName = TomShane.Neoforce.External.Zip.Shared.StringFromBuffer(block, 0, block.Length);
|
||||
|
||||
zde._Extra = new byte[extraFieldLength];
|
||||
n = s.Read(zde._Extra, 0, zde._Extra.Length);
|
||||
|
||||
block = new byte[commentLength];
|
||||
n = s.Read(block, 0, block.Length);
|
||||
zde._Comment = TomShane.Neoforce.External.Zip.Shared.StringFromBuffer(block, 0, block.Length);
|
||||
|
||||
return zde;
|
||||
}
|
||||
|
||||
private static bool SignatureIsNotValid(int signature)
|
||||
{
|
||||
return (signature != ZipDirEntrySignature);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
699
Neoforce/External/Zip/ZipEntry.cs
vendored
699
Neoforce/External/Zip/ZipEntry.cs
vendored
@@ -1,699 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace TomShane.Neoforce.External.Zip
|
||||
{
|
||||
internal class ZipEntry
|
||||
{
|
||||
|
||||
private const int ZipEntrySignature = 0x04034b50;
|
||||
private const int ZipEntryDataDescriptorSignature= 0x08074b50;
|
||||
|
||||
private bool _Debug = false;
|
||||
|
||||
private DateTime _LastModified;
|
||||
public DateTime LastModified
|
||||
{
|
||||
get { return _LastModified; }
|
||||
}
|
||||
|
||||
// when this is set, we trim the volume (eg C:\) off any fully-qualified pathname,
|
||||
// before writing the ZipEntry into the ZipFile.
|
||||
private bool _TrimVolumeFromFullyQualifiedPaths= true; // by default, trim them.
|
||||
public bool TrimVolumeFromFullyQualifiedPaths
|
||||
{
|
||||
get { return _TrimVolumeFromFullyQualifiedPaths; }
|
||||
set { _TrimVolumeFromFullyQualifiedPaths= value; }
|
||||
}
|
||||
|
||||
private string _FileName;
|
||||
public string FileName
|
||||
{
|
||||
get { return _FileName; }
|
||||
}
|
||||
|
||||
private Int16 _VersionNeeded;
|
||||
public Int16 VersionNeeded
|
||||
{
|
||||
get { return _VersionNeeded; }
|
||||
}
|
||||
|
||||
private Int16 _BitField;
|
||||
public Int16 BitField
|
||||
{
|
||||
get { return _BitField; }
|
||||
}
|
||||
|
||||
private Int16 _CompressionMethod;
|
||||
public Int16 CompressionMethod
|
||||
{
|
||||
get { return _CompressionMethod; }
|
||||
}
|
||||
|
||||
private Int32 _CompressedSize;
|
||||
public Int32 CompressedSize
|
||||
{
|
||||
get { return _CompressedSize; }
|
||||
}
|
||||
|
||||
private Int32 _UncompressedSize;
|
||||
public Int32 UncompressedSize
|
||||
{
|
||||
get { return _UncompressedSize; }
|
||||
}
|
||||
|
||||
public Double CompressionRatio
|
||||
{
|
||||
get
|
||||
{
|
||||
return 100 * (1.0 - (1.0 * CompressedSize) / (1.0 * UncompressedSize));
|
||||
}
|
||||
}
|
||||
|
||||
private Int32 _LastModDateTime;
|
||||
private Int32 _Crc32;
|
||||
private byte[] _Extra;
|
||||
|
||||
private byte[] __filedata;
|
||||
private byte[] _FileData
|
||||
{
|
||||
get
|
||||
{
|
||||
if (__filedata == null)
|
||||
{
|
||||
}
|
||||
return __filedata;
|
||||
}
|
||||
}
|
||||
|
||||
private System.IO.MemoryStream _UnderlyingMemoryStream;
|
||||
private System.IO.Compression.DeflateStream _CompressedStream;
|
||||
private System.IO.Compression.DeflateStream CompressedStream
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_CompressedStream == null)
|
||||
{
|
||||
_UnderlyingMemoryStream = new System.IO.MemoryStream();
|
||||
bool LeaveUnderlyingStreamOpen = true;
|
||||
_CompressedStream = new System.IO.Compression.DeflateStream(_UnderlyingMemoryStream,
|
||||
System.IO.Compression.CompressionMode.Compress,
|
||||
LeaveUnderlyingStreamOpen);
|
||||
}
|
||||
return _CompressedStream;
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] _header;
|
||||
internal byte[] Header
|
||||
{
|
||||
get
|
||||
{
|
||||
return _header;
|
||||
}
|
||||
}
|
||||
|
||||
private int _RelativeOffsetOfHeader;
|
||||
|
||||
|
||||
private static bool ReadHeader(System.IO.Stream s, ZipEntry ze)
|
||||
{
|
||||
int signature = TomShane.Neoforce.External.Zip.Shared.ReadSignature(s);
|
||||
|
||||
// return null if this is not a local file header signature
|
||||
if (SignatureIsNotValid(signature))
|
||||
{
|
||||
s.Seek(-4, System.IO.SeekOrigin.Current);
|
||||
if (ze._Debug) System.Console.WriteLine(" ZipEntry::Read(): Bad signature ({0:X8}) at position {1}", signature, s.Position);
|
||||
return false;
|
||||
}
|
||||
|
||||
byte[] block = new byte[26];
|
||||
int n = s.Read(block, 0, block.Length);
|
||||
if (n != block.Length) return false;
|
||||
|
||||
int i = 0;
|
||||
ze._VersionNeeded = (short)(block[i++] + block[i++] * 256);
|
||||
ze._BitField = (short)(block[i++] + block[i++] * 256);
|
||||
ze._CompressionMethod = (short)(block[i++] + block[i++] * 256);
|
||||
ze._LastModDateTime = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
|
||||
|
||||
// the PKZIP spec says that if bit 3 is set (0x0008), then the CRC, Compressed size, and uncompressed size
|
||||
// come directly after the file data. The only way to find it is to scan the zip archive for the signature of
|
||||
// the Data Descriptor, and presume that that signature does not appear in the (compressed) data of the compressed file.
|
||||
|
||||
if ((ze._BitField & 0x0008) != 0x0008)
|
||||
{
|
||||
ze._Crc32 = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
|
||||
ze._CompressedSize = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
|
||||
ze._UncompressedSize = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
|
||||
}
|
||||
else
|
||||
{
|
||||
// the CRC, compressed size, and uncompressed size are stored later in the stream.
|
||||
// here, we advance the pointer.
|
||||
i += 12;
|
||||
}
|
||||
|
||||
Int16 filenameLength = (short)(block[i++] + block[i++] * 256);
|
||||
Int16 extraFieldLength = (short)(block[i++] + block[i++] * 256);
|
||||
|
||||
block = new byte[filenameLength];
|
||||
n = s.Read(block, 0, block.Length);
|
||||
ze._FileName = TomShane.Neoforce.External.Zip.Shared.StringFromBuffer(block, 0, block.Length);
|
||||
|
||||
ze._Extra = new byte[extraFieldLength];
|
||||
n = s.Read(ze._Extra, 0, ze._Extra.Length);
|
||||
|
||||
// transform the time data into something usable
|
||||
ze._LastModified = TomShane.Neoforce.External.Zip.Shared.PackedToDateTime(ze._LastModDateTime);
|
||||
|
||||
// actually get the compressed size and CRC if necessary
|
||||
if ((ze._BitField & 0x0008) == 0x0008)
|
||||
{
|
||||
long posn = s.Position;
|
||||
long SizeOfDataRead = TomShane.Neoforce.External.Zip.Shared.FindSignature(s, ZipEntryDataDescriptorSignature);
|
||||
if (SizeOfDataRead == -1) return false;
|
||||
|
||||
// read 3x 4-byte fields (CRC, Compressed Size, Uncompressed Size)
|
||||
block = new byte[12];
|
||||
n = s.Read(block, 0, block.Length);
|
||||
if (n != 12) return false;
|
||||
i = 0;
|
||||
ze._Crc32 = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
|
||||
ze._CompressedSize = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
|
||||
ze._UncompressedSize = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
|
||||
|
||||
if (SizeOfDataRead != ze._CompressedSize)
|
||||
throw new Exception("Data format error (bit 3 is set)");
|
||||
|
||||
// seek back to previous position, to read file data
|
||||
s.Seek(posn, System.IO.SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private static bool SignatureIsNotValid(int signature)
|
||||
{
|
||||
return (signature != ZipEntrySignature);
|
||||
}
|
||||
|
||||
|
||||
public static ZipEntry Read(System.IO.Stream s)
|
||||
{
|
||||
return Read(s, false);
|
||||
}
|
||||
|
||||
|
||||
internal static ZipEntry Read(System.IO.Stream s, bool TurnOnDebug)
|
||||
{
|
||||
ZipEntry entry = new ZipEntry();
|
||||
entry._Debug = TurnOnDebug;
|
||||
if (!ReadHeader(s, entry)) return null;
|
||||
|
||||
entry.__filedata = new byte[entry.CompressedSize];
|
||||
int n = s.Read(entry._FileData, 0, entry._FileData.Length);
|
||||
if (n != entry._FileData.Length)
|
||||
{
|
||||
throw new Exception("badly formatted zip file.");
|
||||
}
|
||||
// finally, seek past the (already read) Data descriptor if necessary
|
||||
if ((entry._BitField & 0x0008) == 0x0008)
|
||||
{
|
||||
s.Seek(16, System.IO.SeekOrigin.Current);
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
||||
|
||||
internal static ZipEntry Create(String filename)
|
||||
{
|
||||
ZipEntry entry = new ZipEntry();
|
||||
entry._FileName = filename;
|
||||
|
||||
entry._LastModified = System.IO.File.GetLastWriteTime(filename);
|
||||
// adjust the time if the .NET BCL thinks it is in DST.
|
||||
// see the note elsewhere in this file for more info.
|
||||
if (entry._LastModified.IsDaylightSavingTime())
|
||||
{
|
||||
System.DateTime AdjustedTime = entry._LastModified - new System.TimeSpan(1, 0, 0);
|
||||
entry._LastModDateTime = TomShane.Neoforce.External.Zip.Shared.DateTimeToPacked(AdjustedTime);
|
||||
}
|
||||
else
|
||||
entry._LastModDateTime = TomShane.Neoforce.External.Zip.Shared.DateTimeToPacked(entry._LastModified);
|
||||
|
||||
// we don't actually slurp in the file until the caller invokes Write on this entry.
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Extract()
|
||||
{
|
||||
Extract(".");
|
||||
}
|
||||
|
||||
public void Extract(System.IO.Stream s)
|
||||
{
|
||||
Extract(null, s);
|
||||
}
|
||||
|
||||
public void Extract(string basedir)
|
||||
{
|
||||
Extract(basedir, null);
|
||||
}
|
||||
|
||||
|
||||
internal System.IO.Stream GetStream()
|
||||
{
|
||||
System.IO.MemoryStream memstream = new System.IO.MemoryStream(_FileData);
|
||||
|
||||
if (CompressedSize == UncompressedSize)
|
||||
return memstream;
|
||||
|
||||
return new System.IO.Compression.DeflateStream(
|
||||
memstream, System.IO.Compression.CompressionMode.Decompress);
|
||||
}
|
||||
|
||||
// pass in either basedir or s, but not both.
|
||||
// In other words, you can extract to a stream or to a directory, but not both!
|
||||
private void Extract(string basedir, System.IO.Stream s)
|
||||
{
|
||||
string TargetFile = null;
|
||||
if (basedir != null)
|
||||
{
|
||||
TargetFile = System.IO.Path.Combine(basedir, FileName);
|
||||
|
||||
// check if a directory
|
||||
if (FileName.EndsWith("/"))
|
||||
{
|
||||
if (!System.IO.Directory.Exists(TargetFile))
|
||||
System.IO.Directory.CreateDirectory(TargetFile);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (s != null)
|
||||
{
|
||||
if (FileName.EndsWith("/"))
|
||||
// extract a directory to streamwriter? nothing to do!
|
||||
return;
|
||||
}
|
||||
else throw new Exception("Invalid input.");
|
||||
|
||||
|
||||
using (System.IO.MemoryStream memstream = new System.IO.MemoryStream(_FileData))
|
||||
{
|
||||
|
||||
System.IO.Stream input = null;
|
||||
try
|
||||
{
|
||||
|
||||
if (CompressedSize == UncompressedSize)
|
||||
{
|
||||
// the System.IO.Compression.DeflateStream class does not handle uncompressed data.
|
||||
// so if an entry is not compressed, then we just translate the bytes directly.
|
||||
input = memstream;
|
||||
}
|
||||
else
|
||||
{
|
||||
input = new System.IO.Compression.DeflateStream(memstream, System.IO.Compression.CompressionMode.Decompress);
|
||||
}
|
||||
|
||||
|
||||
if (TargetFile != null)
|
||||
{
|
||||
// ensure the target path exists
|
||||
if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(TargetFile)))
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(TargetFile));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
System.IO.Stream output = null;
|
||||
try
|
||||
{
|
||||
if (TargetFile != null)
|
||||
output = new System.IO.FileStream(TargetFile, System.IO.FileMode.CreateNew);
|
||||
else
|
||||
output = s;
|
||||
|
||||
|
||||
byte[] bytes = new byte[4096];
|
||||
int n;
|
||||
|
||||
if (_Debug)
|
||||
{
|
||||
Console.WriteLine("{0}: _FileData.Length= {1}", TargetFile, _FileData.Length);
|
||||
Console.WriteLine("{0}: memstream.Position: {1}", TargetFile, memstream.Position);
|
||||
n = _FileData.Length;
|
||||
if (n > 1000)
|
||||
{
|
||||
n = 500;
|
||||
Console.WriteLine("{0}: truncating dump from {1} to {2} bytes...", TargetFile, _FileData.Length, n);
|
||||
}
|
||||
for (int j = 0; j < n; j += 2)
|
||||
{
|
||||
if ((j > 0) && (j % 40 == 0))
|
||||
System.Console.WriteLine();
|
||||
System.Console.Write(" {0:X2}", _FileData[j]);
|
||||
if (j + 1 < n)
|
||||
System.Console.Write("{0:X2}", _FileData[j + 1]);
|
||||
}
|
||||
System.Console.WriteLine("\n");
|
||||
}
|
||||
|
||||
n = 1; // anything non-zero
|
||||
while (n != 0)
|
||||
{
|
||||
if (_Debug) Console.WriteLine("{0}: about to read...", TargetFile);
|
||||
n = input.Read(bytes, 0, bytes.Length);
|
||||
if (_Debug) Console.WriteLine("{0}: got {1} bytes", TargetFile, n);
|
||||
if (n > 0)
|
||||
{
|
||||
if (_Debug) Console.WriteLine("{0}: about to write...", TargetFile);
|
||||
output.Write(bytes, 0, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
// we only close the output stream if we opened it.
|
||||
if ((output != null) && (TargetFile != null))
|
||||
{
|
||||
output.Close();
|
||||
output.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
if (TargetFile != null)
|
||||
{
|
||||
// We may have to adjust the last modified time to compensate
|
||||
// for differences in how the .NET Base Class Library deals
|
||||
// with daylight saving time (DST) versus how the Windows
|
||||
// filesystem deals with daylight saving time. See
|
||||
// http://blogs.msdn.com/oldnewthing/archive/2003/10/24/55413.aspx for some context.
|
||||
|
||||
// in a nutshell: Daylight savings time rules change regularly. In
|
||||
// 2007, for example, the inception week of DST changed. In 1977,
|
||||
// DST was in place all year round. in 1945, likewise. And so on.
|
||||
// Win32 does not attempt to guess which time zone rules were in
|
||||
// effect at the time in question. It will render a time as
|
||||
// "standard time" and allow the app to change to DST as necessary.
|
||||
// .NET makes a different choice.
|
||||
|
||||
// -------------------------------------------------------
|
||||
// Compare the output of FileInfo.LastWriteTime.ToString("f") with
|
||||
// what you see in the property sheet for a file that was last
|
||||
// written to on the other side of the DST transition. For example,
|
||||
// suppose the file was last modified on October 17, during DST but
|
||||
// DST is not currently in effect. Explorer's file properties
|
||||
// reports Thursday, October 17, 2003, 8:45:38 AM, but .NETs
|
||||
// FileInfo reports Thursday, October 17, 2003, 9:45 AM.
|
||||
|
||||
// Win32 says, "Thursday, October 17, 2002 8:45:38 AM PST". Note:
|
||||
// Pacific STANDARD Time. Even though October 17 of that year
|
||||
// occurred during Pacific Daylight Time, Win32 displays the time as
|
||||
// standard time because that's what time it is NOW.
|
||||
|
||||
// .NET BCL assumes that the current DST rules were in place at the
|
||||
// time in question. So, .NET says, "Well, if the rules in effect
|
||||
// now were also in effect on October 17, 2003, then that would be
|
||||
// daylight time" so it displays "Thursday, October 17, 2003, 9:45
|
||||
// AM PDT" - daylight time.
|
||||
|
||||
// So .NET gives a value which is more intuitively correct, but is
|
||||
// also potentially incorrect, and which is not invertible. Win32
|
||||
// gives a value which is intuitively incorrect, but is strictly
|
||||
// correct.
|
||||
// -------------------------------------------------------
|
||||
|
||||
// With this adjustment, I add one hour to the tweaked .NET time, if
|
||||
// necessary. That is to say, if the time in question had occurred
|
||||
// in what the .NET BCL assumed to be DST (an assumption that may be
|
||||
// wrong given the constantly changing DST rules).
|
||||
|
||||
#if !XBOX
|
||||
if (LastModified.IsDaylightSavingTime())
|
||||
{
|
||||
DateTime AdjustedLastModified = LastModified + new System.TimeSpan(1, 0, 0);
|
||||
System.IO.File.SetLastWriteTime(TargetFile, AdjustedLastModified);
|
||||
}
|
||||
else
|
||||
System.IO.File.SetLastWriteTime(TargetFile, LastModified);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
// we only close the output stream if we opened it.
|
||||
// we cannot use using() here because in some cases we do not want to Dispose the stream!
|
||||
if ((input != null) && (input != memstream))
|
||||
{
|
||||
input.Close();
|
||||
input.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal void WriteCentralDirectoryEntry(System.IO.Stream s)
|
||||
{
|
||||
byte[] bytes = new byte[4096];
|
||||
int i = 0;
|
||||
// signature
|
||||
bytes[i++] = (byte)(ZipDirEntry.ZipDirEntrySignature & 0x000000FF);
|
||||
bytes[i++] = (byte)((ZipDirEntry.ZipDirEntrySignature & 0x0000FF00) >> 8);
|
||||
bytes[i++] = (byte)((ZipDirEntry.ZipDirEntrySignature & 0x00FF0000) >> 16);
|
||||
bytes[i++] = (byte)((ZipDirEntry.ZipDirEntrySignature & 0xFF000000) >> 24);
|
||||
|
||||
// Version Made By
|
||||
bytes[i++] = Header[4];
|
||||
bytes[i++] = Header[5];
|
||||
|
||||
// Version Needed, Bitfield, compression method, lastmod,
|
||||
// crc, sizes, filename length and extra field length -
|
||||
// are all the same as the local file header. So just copy them
|
||||
int j = 0;
|
||||
for (j = 0; j < 26; j++)
|
||||
bytes[i + j] = Header[4 + j];
|
||||
|
||||
i += j; // positioned at next available byte
|
||||
|
||||
// File Comment Length
|
||||
bytes[i++] = 0;
|
||||
bytes[i++] = 0;
|
||||
|
||||
// Disk number start
|
||||
bytes[i++] = 0;
|
||||
bytes[i++] = 0;
|
||||
|
||||
// internal file attrs
|
||||
bytes[i++] = 1;
|
||||
bytes[i++] = 0;
|
||||
|
||||
// external file attrs
|
||||
bytes[i++] = 0x20;
|
||||
bytes[i++] = 0;
|
||||
bytes[i++] = 0xb6;
|
||||
bytes[i++] = 0x81;
|
||||
|
||||
// relative offset of local header (I think this can be zero)
|
||||
bytes[i++] = (byte)(_RelativeOffsetOfHeader & 0x000000FF);
|
||||
bytes[i++] = (byte)((_RelativeOffsetOfHeader & 0x0000FF00) >> 8);
|
||||
bytes[i++] = (byte)((_RelativeOffsetOfHeader & 0x00FF0000) >> 16);
|
||||
bytes[i++] = (byte)((_RelativeOffsetOfHeader & 0xFF000000) >> 24);
|
||||
|
||||
if (_Debug) System.Console.WriteLine("\ninserting filename into CDS: (length= {0})", Header.Length - 30);
|
||||
// actual filename (starts at offset 34 in header)
|
||||
for (j = 0; j < Header.Length - 30; j++)
|
||||
{
|
||||
bytes[i + j] = Header[30 + j];
|
||||
if (_Debug) System.Console.Write(" {0:X2}", bytes[i + j]);
|
||||
}
|
||||
if (_Debug) System.Console.WriteLine();
|
||||
i += j;
|
||||
|
||||
s.Write(bytes, 0, i);
|
||||
}
|
||||
|
||||
|
||||
private void WriteHeader(System.IO.Stream s, byte[] bytes)
|
||||
{
|
||||
// write the header info
|
||||
|
||||
int i = 0;
|
||||
// signature
|
||||
bytes[i++] = (byte)(ZipEntrySignature & 0x000000FF);
|
||||
bytes[i++] = (byte)((ZipEntrySignature & 0x0000FF00) >> 8);
|
||||
bytes[i++] = (byte)((ZipEntrySignature & 0x00FF0000) >> 16);
|
||||
bytes[i++] = (byte)((ZipEntrySignature & 0xFF000000) >> 24);
|
||||
|
||||
// version needed
|
||||
Int16 FixedVersionNeeded = 0x14; // from examining existing zip files
|
||||
bytes[i++] = (byte)(FixedVersionNeeded & 0x00FF);
|
||||
bytes[i++] = (byte)((FixedVersionNeeded & 0xFF00) >> 8);
|
||||
|
||||
// bitfield
|
||||
Int16 BitField = 0x00; // from examining existing zip files
|
||||
bytes[i++] = (byte)(BitField & 0x00FF);
|
||||
bytes[i++] = (byte)((BitField & 0xFF00) >> 8);
|
||||
|
||||
// compression method
|
||||
Int16 CompressionMethod = 0x08; // 0x08 = Deflate
|
||||
bytes[i++] = (byte)(CompressionMethod & 0x00FF);
|
||||
bytes[i++] = (byte)((CompressionMethod & 0xFF00) >> 8);
|
||||
|
||||
// LastMod
|
||||
bytes[i++] = (byte)(_LastModDateTime & 0x000000FF);
|
||||
bytes[i++] = (byte)((_LastModDateTime & 0x0000FF00) >> 8);
|
||||
bytes[i++] = (byte)((_LastModDateTime & 0x00FF0000) >> 16);
|
||||
bytes[i++] = (byte)((_LastModDateTime & 0xFF000000) >> 24);
|
||||
|
||||
// CRC32 (Int32)
|
||||
CRC32 crc32 = new CRC32();
|
||||
UInt32 crc = 0;
|
||||
using (System.IO.Stream input = System.IO.File.OpenRead(FileName))
|
||||
{
|
||||
crc = crc32.GetCrc32AndCopy(input, CompressedStream);
|
||||
}
|
||||
CompressedStream.Close(); // to get the footer bytes written to the underlying stream
|
||||
|
||||
bytes[i++] = (byte)(crc & 0x000000FF);
|
||||
bytes[i++] = (byte)((crc & 0x0000FF00) >> 8);
|
||||
bytes[i++] = (byte)((crc & 0x00FF0000) >> 16);
|
||||
bytes[i++] = (byte)((crc & 0xFF000000) >> 24);
|
||||
|
||||
// CompressedSize (Int32)
|
||||
Int32 isz = (Int32)_UnderlyingMemoryStream.Length;
|
||||
UInt32 sz = (UInt32)isz;
|
||||
bytes[i++] = (byte)(sz & 0x000000FF);
|
||||
bytes[i++] = (byte)((sz & 0x0000FF00) >> 8);
|
||||
bytes[i++] = (byte)((sz & 0x00FF0000) >> 16);
|
||||
bytes[i++] = (byte)((sz & 0xFF000000) >> 24);
|
||||
|
||||
// UncompressedSize (Int32)
|
||||
if (_Debug) System.Console.WriteLine("Uncompressed Size: {0}", crc32.TotalBytesRead);
|
||||
bytes[i++] = (byte)(crc32.TotalBytesRead & 0x000000FF);
|
||||
bytes[i++] = (byte)((crc32.TotalBytesRead & 0x0000FF00) >> 8);
|
||||
bytes[i++] = (byte)((crc32.TotalBytesRead & 0x00FF0000) >> 16);
|
||||
bytes[i++] = (byte)((crc32.TotalBytesRead & 0xFF000000) >> 24);
|
||||
|
||||
// filename length (Int16)
|
||||
Int16 length = (Int16)FileName.Length;
|
||||
// see note below about TrimVolumeFromFullyQualifiedPaths.
|
||||
if ( (TrimVolumeFromFullyQualifiedPaths) && (FileName[1]==':') && (FileName[2]=='\\')) length-=3;
|
||||
bytes[i++] = (byte)(length & 0x00FF);
|
||||
bytes[i++] = (byte)((length & 0xFF00) >> 8);
|
||||
|
||||
// extra field length (short)
|
||||
Int16 ExtraFieldLength = 0x00;
|
||||
bytes[i++] = (byte)(ExtraFieldLength & 0x00FF);
|
||||
bytes[i++] = (byte)((ExtraFieldLength & 0xFF00) >> 8);
|
||||
|
||||
// Tue, 27 Mar 2007 16:35
|
||||
|
||||
// Creating a zip that contains entries with "fully qualified" pathnames
|
||||
// can result in a zip archive that is unreadable by Windows Explorer.
|
||||
// Such archives are valid according to other tools but not to explorer.
|
||||
// To avoid this, we can trim off the leading volume name and slash (eg
|
||||
// c:\) when creating (writing) a zip file. We do this by default and we
|
||||
// leave the old behavior available with the
|
||||
// TrimVolumeFromFullyQualifiedPaths flag - set it to false to get the old
|
||||
// behavior. It only affects zip creation.
|
||||
|
||||
// actual filename
|
||||
char[] c = ( (TrimVolumeFromFullyQualifiedPaths) && (FileName[1]==':') && (FileName[2]=='\\')) ?
|
||||
FileName.Substring(3).ToCharArray() : // trim off volume letter, colon, and slash
|
||||
FileName.ToCharArray();
|
||||
int j = 0;
|
||||
|
||||
if (_Debug)
|
||||
{
|
||||
System.Console.WriteLine("local header: writing filename, {0} chars", c.Length);
|
||||
System.Console.WriteLine("starting offset={0}", i);
|
||||
}
|
||||
for (j = 0; (j < c.Length) && (i + j < bytes.Length); j++)
|
||||
{
|
||||
bytes[i + j] = System.BitConverter.GetBytes(c[j])[0];
|
||||
if (_Debug) System.Console.Write(" {0:X2}", bytes[i + j]);
|
||||
}
|
||||
if (_Debug) System.Console.WriteLine();
|
||||
|
||||
i += j;
|
||||
|
||||
// extra field (we always write nothing in this implementation)
|
||||
// ;;
|
||||
|
||||
// remember the file offset of this header
|
||||
_RelativeOffsetOfHeader = (int)s.Length;
|
||||
|
||||
|
||||
if (_Debug)
|
||||
{
|
||||
System.Console.WriteLine("\nAll header data:");
|
||||
for (j = 0; j < i; j++)
|
||||
System.Console.Write(" {0:X2}", bytes[j]);
|
||||
System.Console.WriteLine();
|
||||
}
|
||||
// finally, write the header to the stream
|
||||
s.Write(bytes, 0, i);
|
||||
|
||||
// preserve this header data for use with the central directory structure.
|
||||
_header = new byte[i];
|
||||
if (_Debug) System.Console.WriteLine("preserving header of {0} bytes", _header.Length);
|
||||
for (j = 0; j < i; j++)
|
||||
_header[j] = bytes[j];
|
||||
|
||||
}
|
||||
|
||||
|
||||
internal void Write(System.IO.Stream s)
|
||||
{
|
||||
byte[] bytes = new byte[4096];
|
||||
int n;
|
||||
|
||||
// write the header:
|
||||
WriteHeader(s, bytes);
|
||||
|
||||
// write the actual file data:
|
||||
_UnderlyingMemoryStream.Position = 0;
|
||||
|
||||
if (_Debug)
|
||||
{
|
||||
Console.WriteLine("{0}: writing compressed data to zipfile...", FileName);
|
||||
Console.WriteLine("{0}: total data length: {1}", FileName, _UnderlyingMemoryStream.Length);
|
||||
}
|
||||
while ((n = _UnderlyingMemoryStream.Read(bytes, 0, bytes.Length)) != 0)
|
||||
{
|
||||
|
||||
if (_Debug)
|
||||
{
|
||||
Console.WriteLine("{0}: transferring {1} bytes...", FileName, n);
|
||||
|
||||
for (int j = 0; j < n; j += 2)
|
||||
{
|
||||
if ((j > 0) && (j % 40 == 0))
|
||||
System.Console.WriteLine();
|
||||
System.Console.Write(" {0:X2}", bytes[j]);
|
||||
if (j + 1 < n)
|
||||
System.Console.Write("{0:X2}", bytes[j + 1]);
|
||||
}
|
||||
System.Console.WriteLine("\n");
|
||||
}
|
||||
|
||||
s.Write(bytes, 0, n);
|
||||
}
|
||||
|
||||
//_CompressedStream.Close();
|
||||
//_CompressedStream= null;
|
||||
_UnderlyingMemoryStream.Close();
|
||||
_UnderlyingMemoryStream = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
505
Neoforce/External/Zip/ZipFile.cs
vendored
505
Neoforce/External/Zip/ZipFile.cs
vendored
@@ -1,505 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace TomShane.Neoforce.External.Zip
|
||||
{
|
||||
|
||||
internal class ZipFile : System.Collections.Generic.IEnumerable<ZipEntry>,
|
||||
IDisposable
|
||||
{
|
||||
private string _name;
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
// when this is set, we trim the volume (eg C:) off any fully-qualified pathname,
|
||||
// before writing the ZipEntry into the ZipFile.
|
||||
// We default this to true. This allows Windows Explorer to read the zip archives properly.
|
||||
private bool _TrimVolumeFromFullyQualifiedPaths= true;
|
||||
public bool TrimVolumeFromFullyQualifiedPaths
|
||||
{
|
||||
get { return _TrimVolumeFromFullyQualifiedPaths; }
|
||||
set { _TrimVolumeFromFullyQualifiedPaths= value; }
|
||||
}
|
||||
|
||||
private System.IO.Stream ReadStream
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_readstream == null)
|
||||
{
|
||||
_readstream = System.IO.File.OpenRead(_name);
|
||||
}
|
||||
return _readstream;
|
||||
}
|
||||
}
|
||||
|
||||
private System.IO.FileStream WriteStream
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_writestream == null)
|
||||
{
|
||||
_writestream = new System.IO.FileStream(_name, System.IO.FileMode.CreateNew);
|
||||
}
|
||||
return _writestream;
|
||||
}
|
||||
}
|
||||
|
||||
private ZipFile() { }
|
||||
|
||||
|
||||
#region For Writing Zip Files
|
||||
|
||||
public ZipFile(string NewZipFileName)
|
||||
{
|
||||
// create a new zipfile
|
||||
_name = NewZipFileName;
|
||||
if (System.IO.File.Exists(_name))
|
||||
throw new System.Exception(String.Format("That file ({0}) already exists.", NewZipFileName));
|
||||
_entries = new System.Collections.Generic.List<ZipEntry>();
|
||||
}
|
||||
|
||||
|
||||
public void AddItem(string FileOrDirectoryName)
|
||||
{
|
||||
AddItem(FileOrDirectoryName, false);
|
||||
}
|
||||
|
||||
public void AddItem(string FileOrDirectoryName, bool WantVerbose)
|
||||
{
|
||||
if (System.IO.File.Exists(FileOrDirectoryName))
|
||||
AddFile(FileOrDirectoryName, WantVerbose);
|
||||
else if (System.IO.Directory.Exists(FileOrDirectoryName))
|
||||
AddDirectory(FileOrDirectoryName, WantVerbose);
|
||||
|
||||
else
|
||||
throw new Exception(String.Format("That file or directory ({0}) does not exist!", FileOrDirectoryName));
|
||||
}
|
||||
|
||||
public void AddFile(string FileName)
|
||||
{
|
||||
AddFile(FileName, false);
|
||||
}
|
||||
|
||||
public void AddFile(string FileName, bool WantVerbose)
|
||||
{
|
||||
ZipEntry ze = ZipEntry.Create(FileName);
|
||||
ze.TrimVolumeFromFullyQualifiedPaths= TrimVolumeFromFullyQualifiedPaths;
|
||||
if (WantVerbose) Console.WriteLine("adding {0}...", FileName);
|
||||
ze.Write(WriteStream);
|
||||
_entries.Add(ze);
|
||||
}
|
||||
|
||||
public void AddDirectory(string DirectoryName)
|
||||
{
|
||||
AddDirectory(DirectoryName, false);
|
||||
}
|
||||
|
||||
public void AddDirectory(string DirectoryName, bool WantVerbose)
|
||||
{
|
||||
String[] filenames = System.IO.Directory.GetFiles(DirectoryName);
|
||||
foreach (String filename in filenames)
|
||||
{
|
||||
if (WantVerbose) Console.WriteLine("adding {0}...", filename);
|
||||
AddFile(filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Save()
|
||||
{
|
||||
WriteCentralDirectoryStructure();
|
||||
WriteStream.Close();
|
||||
_writestream = null;
|
||||
}
|
||||
|
||||
|
||||
private void WriteCentralDirectoryStructure()
|
||||
{
|
||||
// the central directory structure
|
||||
long Start = WriteStream.Length;
|
||||
foreach (ZipEntry e in _entries)
|
||||
{
|
||||
e.WriteCentralDirectoryEntry(WriteStream);
|
||||
}
|
||||
long Finish = WriteStream.Length;
|
||||
|
||||
// now, the footer
|
||||
WriteCentralDirectoryFooter(Start, Finish);
|
||||
}
|
||||
|
||||
|
||||
private void WriteCentralDirectoryFooter(long StartOfCentralDirectory, long EndOfCentralDirectory)
|
||||
{
|
||||
byte[] bytes = new byte[1024];
|
||||
int i = 0;
|
||||
// signature
|
||||
UInt32 EndOfCentralDirectorySignature = 0x06054b50;
|
||||
bytes[i++] = (byte)(EndOfCentralDirectorySignature & 0x000000FF);
|
||||
bytes[i++] = (byte)((EndOfCentralDirectorySignature & 0x0000FF00) >> 8);
|
||||
bytes[i++] = (byte)((EndOfCentralDirectorySignature & 0x00FF0000) >> 16);
|
||||
bytes[i++] = (byte)((EndOfCentralDirectorySignature & 0xFF000000) >> 24);
|
||||
|
||||
// number of this disk
|
||||
bytes[i++] = 0;
|
||||
bytes[i++] = 0;
|
||||
|
||||
// number of the disk with the start of the central directory
|
||||
bytes[i++] = 0;
|
||||
bytes[i++] = 0;
|
||||
|
||||
// total number of entries in the central dir on this disk
|
||||
bytes[i++] = (byte)(_entries.Count & 0x00FF);
|
||||
bytes[i++] = (byte)((_entries.Count & 0xFF00) >> 8);
|
||||
|
||||
// total number of entries in the central directory
|
||||
bytes[i++] = (byte)(_entries.Count & 0x00FF);
|
||||
bytes[i++] = (byte)((_entries.Count & 0xFF00) >> 8);
|
||||
|
||||
// size of the central directory
|
||||
Int32 SizeOfCentralDirectory = (Int32)(EndOfCentralDirectory - StartOfCentralDirectory);
|
||||
bytes[i++] = (byte)(SizeOfCentralDirectory & 0x000000FF);
|
||||
bytes[i++] = (byte)((SizeOfCentralDirectory & 0x0000FF00) >> 8);
|
||||
bytes[i++] = (byte)((SizeOfCentralDirectory & 0x00FF0000) >> 16);
|
||||
bytes[i++] = (byte)((SizeOfCentralDirectory & 0xFF000000) >> 24);
|
||||
|
||||
// offset of the start of the central directory
|
||||
Int32 StartOffset = (Int32)StartOfCentralDirectory; // cast down from Long
|
||||
bytes[i++] = (byte)(StartOffset & 0x000000FF);
|
||||
bytes[i++] = (byte)((StartOffset & 0x0000FF00) >> 8);
|
||||
bytes[i++] = (byte)((StartOffset & 0x00FF0000) >> 16);
|
||||
bytes[i++] = (byte)((StartOffset & 0xFF000000) >> 24);
|
||||
|
||||
// zip comment length
|
||||
bytes[i++] = 0;
|
||||
bytes[i++] = 0;
|
||||
|
||||
WriteStream.Write(bytes, 0, i);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region For Reading Zip Files
|
||||
|
||||
internal static ZipFile Read(string zipfilename)
|
||||
{
|
||||
return Read(zipfilename, false);
|
||||
}
|
||||
|
||||
internal static ZipFile Read(string zipfilename, bool TurnOnDebug)
|
||||
{
|
||||
|
||||
ZipFile zf = new ZipFile();
|
||||
zf._Debug = TurnOnDebug;
|
||||
zf._name = zipfilename;
|
||||
zf._entries = new System.Collections.Generic.List<ZipEntry>();
|
||||
ZipEntry e;
|
||||
while ((e = ZipEntry.Read(zf.ReadStream, zf._Debug)) != null)
|
||||
{
|
||||
if (zf._Debug) System.Console.WriteLine(" ZipFile::Read(): ZipEntry: {0}", e.FileName);
|
||||
zf._entries.Add(e);
|
||||
}
|
||||
|
||||
// read the zipfile's central directory structure here.
|
||||
zf._direntries = new System.Collections.Generic.List<ZipDirEntry>();
|
||||
|
||||
ZipDirEntry de;
|
||||
while ((de = ZipDirEntry.Read(zf.ReadStream, zf._Debug)) != null)
|
||||
{
|
||||
if (zf._Debug) System.Console.WriteLine(" ZipFile::Read(): ZipDirEntry: {0}", de.FileName);
|
||||
zf._direntries.Add(de);
|
||||
}
|
||||
|
||||
return zf;
|
||||
}
|
||||
|
||||
public System.Collections.Generic.IEnumerator<ZipEntry> GetEnumerator()
|
||||
{
|
||||
foreach (ZipEntry e in _entries)
|
||||
yield return e;
|
||||
}
|
||||
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
|
||||
public void ExtractAll(string path)
|
||||
{
|
||||
ExtractAll(path, false);
|
||||
}
|
||||
|
||||
|
||||
public void ExtractAll(string path, bool WantVerbose)
|
||||
{
|
||||
bool header = WantVerbose;
|
||||
foreach (ZipEntry e in _entries)
|
||||
{
|
||||
if (header)
|
||||
{
|
||||
System.Console.WriteLine("\n{1,-22} {2,-6} {3,4} {4,-8} {0}",
|
||||
"Name", "Modified", "Size", "Ratio", "Packed");
|
||||
System.Console.WriteLine(new System.String('-', 72));
|
||||
header = false;
|
||||
}
|
||||
if (WantVerbose)
|
||||
System.Console.WriteLine("{1,-22} {2,-6} {3,4:F0}% {4,-8} {0}",
|
||||
e.FileName,
|
||||
e.LastModified.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
e.UncompressedSize,
|
||||
e.CompressionRatio,
|
||||
e.CompressedSize);
|
||||
e.Extract(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Extract(string filename)
|
||||
{
|
||||
this[filename].Extract();
|
||||
}
|
||||
|
||||
|
||||
public void Extract(string filename, System.IO.Stream s)
|
||||
{
|
||||
this[filename].Extract(s);
|
||||
}
|
||||
|
||||
|
||||
public ZipEntry this[String filename]
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (ZipEntry e in _entries)
|
||||
{
|
||||
if (e.FileName == filename) return e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
// the destructor
|
||||
~ZipFile()
|
||||
{
|
||||
// call Dispose with false. Since we're in the
|
||||
// destructor call, the managed resources will be
|
||||
// disposed of anyways.
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// dispose of the managed and unmanaged resources
|
||||
Dispose(true);
|
||||
|
||||
// tell the GC that the Finalize process no longer needs
|
||||
// to be run for this object.
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
|
||||
protected virtual void Dispose(bool disposeManagedResources)
|
||||
{
|
||||
if (!this._disposed)
|
||||
{
|
||||
if (disposeManagedResources)
|
||||
{
|
||||
// dispose managed resources
|
||||
if (_readstream != null)
|
||||
{
|
||||
_readstream.Dispose();
|
||||
_readstream = null;
|
||||
}
|
||||
if (_writestream != null)
|
||||
{
|
||||
_writestream.Dispose();
|
||||
_writestream = null;
|
||||
}
|
||||
}
|
||||
this._disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private System.IO.Stream _readstream;
|
||||
private System.IO.FileStream _writestream;
|
||||
private bool _Debug = false;
|
||||
private bool _disposed = false;
|
||||
private System.Collections.Generic.List<ZipEntry> _entries = null;
|
||||
private System.Collections.Generic.List<ZipDirEntry> _direntries = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#region More Info
|
||||
// Example usage:
|
||||
// 1. Extracting all files from a Zip file:
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// using(ZipFile zip= ZipFile.Read(ZipFile))
|
||||
// {
|
||||
// zip.ExtractAll(TargetDirectory, true);
|
||||
// }
|
||||
// }
|
||||
// catch (System.Exception ex1)
|
||||
// {
|
||||
// System.Console.Error.WriteLine("exception: " + ex1);
|
||||
// }
|
||||
//
|
||||
// 2. Extracting files from a zip individually:
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// using(ZipFile zip= ZipFile.Read(ZipFile))
|
||||
// {
|
||||
// foreach (ZipEntry e in zip)
|
||||
// {
|
||||
// e.Extract(TargetDirectory);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// catch (System.Exception ex1)
|
||||
// {
|
||||
// System.Console.Error.WriteLine("exception: " + ex1);
|
||||
// }
|
||||
//
|
||||
// 3. Creating a zip archive:
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// using(ZipFile zip= new ZipFile(NewZipFile))
|
||||
// {
|
||||
//
|
||||
// String[] filenames= System.IO.Directory.GetFiles(Directory);
|
||||
// foreach (String filename in filenames)
|
||||
// {
|
||||
// zip.Add(filename);
|
||||
// }
|
||||
//
|
||||
// zip.Save();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// catch (System.Exception ex1)
|
||||
// {
|
||||
// System.Console.Error.WriteLine("exception: " + ex1);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// ==================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
// Information on the ZIP format:
|
||||
//
|
||||
// From
|
||||
// http://www.pkware.com/business_and_developers/developer/popups/appnote.txt
|
||||
//
|
||||
// Overall .ZIP file format:
|
||||
//
|
||||
// [local file header 1]
|
||||
// [file data 1]
|
||||
// [data descriptor 1] ** sometimes
|
||||
// .
|
||||
// .
|
||||
// .
|
||||
// [local file header n]
|
||||
// [file data n]
|
||||
// [data descriptor n] ** sometimes
|
||||
// [archive decryption header]
|
||||
// [archive extra data record]
|
||||
// [central directory]
|
||||
// [zip64 end of central directory record]
|
||||
// [zip64 end of central directory locator]
|
||||
// [end of central directory record]
|
||||
//
|
||||
// Local File Header format:
|
||||
// local file header signature 4 bytes (0x04034b50)
|
||||
// version needed to extract 2 bytes
|
||||
// general purpose bit flag 2 bytes
|
||||
// compression method 2 bytes
|
||||
// last mod file time 2 bytes
|
||||
// last mod file date 2 bytes
|
||||
// crc-32 4 bytes
|
||||
// compressed size 4 bytes
|
||||
// uncompressed size 4 bytes
|
||||
// file name length 2 bytes
|
||||
// extra field length 2 bytes
|
||||
// file name varies
|
||||
// extra field varies
|
||||
//
|
||||
//
|
||||
// Data descriptor: (used only when bit 3 of the general purpose bitfield is set)
|
||||
// local file header signature 4 bytes (0x08074b50)
|
||||
// crc-32 4 bytes
|
||||
// compressed size 4 bytes
|
||||
// uncompressed size 4 bytes
|
||||
//
|
||||
//
|
||||
// Central directory structure:
|
||||
//
|
||||
// [file header 1]
|
||||
// .
|
||||
// .
|
||||
// .
|
||||
// [file header n]
|
||||
// [digital signature]
|
||||
//
|
||||
//
|
||||
// File header: (This is ZipDirEntry in the code above)
|
||||
// central file header signature 4 bytes (0x02014b50)
|
||||
// version made by 2 bytes
|
||||
// version needed to extract 2 bytes
|
||||
// general purpose bit flag 2 bytes
|
||||
// compression method 2 bytes
|
||||
// last mod file time 2 bytes
|
||||
// last mod file date 2 bytes
|
||||
// crc-32 4 bytes
|
||||
// compressed size 4 bytes
|
||||
// uncompressed size 4 bytes
|
||||
// file name length 2 bytes
|
||||
// extra field length 2 bytes
|
||||
// file comment length 2 bytes
|
||||
// disk number start 2 bytes
|
||||
// internal file attributes 2 bytes
|
||||
// external file attributes 4 bytes
|
||||
// relative offset of local header 4 bytes
|
||||
// file name (variable size)
|
||||
// extra field (variable size)
|
||||
// file comment (variable size)
|
||||
//
|
||||
// End of central directory record:
|
||||
//
|
||||
// end of central dir signature 4 bytes (0x06054b50)
|
||||
// number of this disk 2 bytes
|
||||
// number of the disk with the
|
||||
// start of the central directory 2 bytes
|
||||
// total number of entries in the
|
||||
// central directory on this disk 2 bytes
|
||||
// total number of entries in
|
||||
// the central directory 2 bytes
|
||||
// size of the central directory 4 bytes
|
||||
// offset of start of central
|
||||
// directory with respect to
|
||||
// the starting disk number 4 bytes
|
||||
// .ZIP file comment length 2 bytes
|
||||
// .ZIP file comment (variable size)
|
||||
//
|
||||
// date and time are packed values, as MSDOS did them
|
||||
// time: bits 0-4 : second
|
||||
// 5-10: minute
|
||||
// 11-15: hour
|
||||
// date bits 0-4 : day
|
||||
// 5-8: month
|
||||
// 9-15 year (since 1980)
|
||||
//
|
||||
// see http://www.vsft.com/hal/dostime.htm
|
||||
|
||||
#endregion
|
||||
@@ -1,139 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: GroupBox.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
public enum GroupBoxType
|
||||
{
|
||||
Normal,
|
||||
Flat
|
||||
}
|
||||
|
||||
public class GroupBox : Container
|
||||
{
|
||||
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private GroupBoxType type = GroupBoxType.Normal;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Properties ////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public virtual GroupBoxType Type
|
||||
{
|
||||
get { return type; }
|
||||
set { type = value; Invalidate(); }
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Construstors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public GroupBox(Manager manager)
|
||||
: base(manager)
|
||||
{
|
||||
CheckLayer(Skin, "Control");
|
||||
CheckLayer(Skin, "Flat");
|
||||
|
||||
CanFocus = false;
|
||||
Passive = true;
|
||||
Width = 64;
|
||||
Height = 64;
|
||||
BackColor = Color.Transparent;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
private void AdjustClientMargins()
|
||||
{
|
||||
SkinLayer layer = this.type == GroupBoxType.Normal ? this.Skin.Layers["Control"] : this.Skin.Layers["Flat"];
|
||||
SpriteFont font = (layer.Text != null && layer.Text.Font != null) ? layer.Text.Font.Resource : null;
|
||||
Vector2 size = font.MeasureString(this.Text);
|
||||
var cm = this.ClientMargins;
|
||||
cm.Top = string.IsNullOrWhiteSpace(this.Text) ? this.ClientTop : (int)size.Y;
|
||||
this.ClientMargins = new Margins(cm.Left, cm.Top, cm.Right, cm.Bottom);
|
||||
}
|
||||
|
||||
protected override void OnTextChanged(EventArgs e)
|
||||
{
|
||||
base.OnTextChanged(e);
|
||||
AdjustClientMargins();
|
||||
}
|
||||
|
||||
protected internal override void OnSkinChanged(EventArgs e)
|
||||
{
|
||||
base.OnSkinChanged(e);
|
||||
AdjustClientMargins();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime)
|
||||
{
|
||||
SkinLayer layer = type == GroupBoxType.Normal ? Skin.Layers["Control"] : Skin.Layers["Flat"];
|
||||
SpriteFont font = (layer.Text != null && layer.Text.Font != null) ? layer.Text.Font.Resource : null;
|
||||
Color col = (layer.Text != null) ? layer.Text.Colors.Enabled : Color.White;
|
||||
Point offset = new Point(layer.Text.OffsetX, layer.Text.OffsetY);
|
||||
Vector2 size = font.MeasureString(Text);
|
||||
size.Y = font.LineSpacing;
|
||||
Rectangle r = new Rectangle(rect.Left, rect.Top + (int)(size.Y / 2), rect.Width, rect.Height - (int)(size.Y / 2));
|
||||
|
||||
renderer.DrawLayer(this, layer, r);
|
||||
|
||||
if (font != null && Text != null && Text != "")
|
||||
{
|
||||
Rectangle bg = new Rectangle(r.Left + offset.X, (r.Top - (int)(size.Y / 2)) + offset.Y, (int)size.X + layer.ContentMargins.Horizontal, (int)size.Y);
|
||||
renderer.DrawLayer(Manager.Skin.Controls["Control"].Layers[0], bg, new Color(64, 64, 64), 0);
|
||||
renderer.DrawString(this, layer, Text, new Rectangle(r.Left, r.Top - (int)(size.Y / 2), (int)(size.X), (int)size.Y), true, 0, 0, false);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: GroupPanel.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
public class GroupPanel: Container
|
||||
{
|
||||
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Properties ////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Construstors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public GroupPanel(Manager manager): base(manager)
|
||||
{
|
||||
CanFocus = false;
|
||||
Passive = true;
|
||||
Width = 64;
|
||||
Height = 64;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime)
|
||||
{
|
||||
SkinLayer layer = Skin.Layers["Control"];
|
||||
SpriteFont font = (layer.Text != null && layer.Text.Font != null) ? layer.Text.Font.Resource : null;
|
||||
Color col = (layer.Text != null) ? layer.Text.Colors.Enabled : Color.White;
|
||||
Point offset = new Point(layer.Text.OffsetX, layer.Text.OffsetY);
|
||||
|
||||
renderer.DrawLayer(this, layer, rect);
|
||||
|
||||
if (font != null && Text != null && Text != "")
|
||||
{
|
||||
renderer.DrawString(this, layer, Text, new Rectangle(rect.Left, rect.Top + layer.ContentMargins.Top, rect.Width, Skin.ClientMargins.Top - layer.ContentMargins.Horizontal), false, offset.X, offset.Y, false);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,197 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: ImageBox.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
public class ImageBox: Control
|
||||
{
|
||||
|
||||
#region //// Fields ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
private Texture2D image = null;
|
||||
private SizeMode sizeMode = SizeMode.Normal;
|
||||
private Rectangle sourceRect = Rectangle.Empty;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Properties ////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public Texture2D Image
|
||||
{
|
||||
get { return image; }
|
||||
set
|
||||
{
|
||||
image = value;
|
||||
sourceRect = new Rectangle(0, 0, image.Width, image.Height);
|
||||
Invalidate();
|
||||
if (!Suspended) OnImageChanged(new EventArgs());
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public Rectangle SourceRect
|
||||
{
|
||||
get { return sourceRect; }
|
||||
set
|
||||
{
|
||||
if (value != null && image != null)
|
||||
{
|
||||
int l = value.Left;
|
||||
int t = value.Top;
|
||||
int w = value.Width;
|
||||
int h = value.Height;
|
||||
|
||||
if (l < 0) l = 0;
|
||||
if (t < 0) t = 0;
|
||||
if (w > image.Width) w = image.Width;
|
||||
if (h > image.Height) h = image.Height;
|
||||
if (l + w > image.Width) w = (image.Width - l);
|
||||
if (t + h > image.Height) h = (image.Height - t);
|
||||
|
||||
sourceRect = new Rectangle(l, t, w, h);
|
||||
}
|
||||
else if (image != null)
|
||||
{
|
||||
sourceRect = new Rectangle(0, 0, image.Width, image.Height);
|
||||
}
|
||||
else
|
||||
{
|
||||
sourceRect = Rectangle.Empty;
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public SizeMode SizeMode
|
||||
{
|
||||
get { return sizeMode; }
|
||||
set
|
||||
{
|
||||
if (value == SizeMode.Auto && image != null)
|
||||
{
|
||||
Width = image.Width;
|
||||
Height = image.Height;
|
||||
}
|
||||
sizeMode = value;
|
||||
Invalidate();
|
||||
if (!Suspended) OnSizeModeChanged(new EventArgs());
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Events ////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public event EventHandler ImageChanged;
|
||||
public event EventHandler SizeModeChanged;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Construstors //////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public ImageBox(Manager manager): base(manager)
|
||||
{
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Methods ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
CanFocus = false;
|
||||
Color = Color.White;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected override void DrawControl(Renderer renderer, Rectangle rect, GameTime gameTime)
|
||||
{
|
||||
if (image != null)
|
||||
{
|
||||
if (sizeMode == SizeMode.Normal)
|
||||
{
|
||||
renderer.Draw(image, rect.X, rect.Y, sourceRect, Color);
|
||||
}
|
||||
else if (sizeMode == SizeMode.Auto)
|
||||
{
|
||||
renderer.Draw(image, rect.X, rect.Y, sourceRect, Color);
|
||||
}
|
||||
else if (sizeMode == SizeMode.Stretched)
|
||||
{
|
||||
renderer.Draw(image, rect, sourceRect, Color);
|
||||
}
|
||||
else if (sizeMode == SizeMode.Centered)
|
||||
{
|
||||
int x = (rect.Width / 2) - (image.Width / 2);
|
||||
int y = (rect.Height / 2) - (image.Height / 2);
|
||||
|
||||
renderer.Draw(image, x, y, sourceRect, Color);
|
||||
}
|
||||
else if (sizeMode == SizeMode.Tiled)
|
||||
{
|
||||
renderer.DrawTileTexture(image, rect, Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected virtual void OnImageChanged(EventArgs e)
|
||||
{
|
||||
if (ImageChanged != null) ImageChanged.Invoke(this, e);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
protected virtual void OnSizeModeChanged(EventArgs e)
|
||||
{
|
||||
if (SizeModeChanged != null) SizeModeChanged.Invoke(this, e);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,732 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Neoforce Controls //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// File: InputSystem.cs //
|
||||
// //
|
||||
// Version: 0.7 //
|
||||
// //
|
||||
// Date: 11/09/2010 //
|
||||
// //
|
||||
// Author: Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// Copyright (c) by Tom Shane //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#region //// Using /////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
namespace TomShane.Neoforce.Controls
|
||||
{
|
||||
|
||||
#region //// Enums /////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
[Flags]
|
||||
public enum InputMethods
|
||||
{
|
||||
None = 0x00,
|
||||
Keyboard = 0x01,
|
||||
Mouse = 0x02,
|
||||
GamePad = 0x04,
|
||||
All = Keyboard | Mouse | 0x04
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public enum MouseButton
|
||||
{
|
||||
None = 0,
|
||||
Left,
|
||||
Right,
|
||||
Middle,
|
||||
XButton1,
|
||||
XButton2
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public enum MouseScrollDirection
|
||||
{
|
||||
None = 0,
|
||||
Down = 1,
|
||||
Up = 2
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public enum GamePadButton
|
||||
{
|
||||
None = 0,
|
||||
Start = 6,
|
||||
Back,
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right,
|
||||
A,
|
||||
B,
|
||||
X,
|
||||
Y,
|
||||
BigButton,
|
||||
LeftShoulder,
|
||||
RightShoulder,
|
||||
LeftTrigger,
|
||||
RightTrigger,
|
||||
LeftStick,
|
||||
RightStick,
|
||||
LeftStickLeft,
|
||||
LeftStickRight,
|
||||
LeftStickUp,
|
||||
LeftStickDown,
|
||||
RightStickLeft,
|
||||
RightStickRight,
|
||||
RightStickUp,
|
||||
RightStickDown
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public enum ActivePlayer
|
||||
{
|
||||
None = -1,
|
||||
One = 0,
|
||||
Two = 1,
|
||||
Three = 2,
|
||||
Four = 3
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endregion
|
||||
|
||||
#region //// Structs ///////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
public struct GamePadVectors
|
||||
{
|
||||
public Vector2 LeftStick;
|
||||