2007-10-31 20:34:09 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.Text;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using Microsoft.Win32;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using CodeImp.DoomBuilder.Controls;
|
|
|
|
using CodeImp.DoomBuilder.Data;
|
|
|
|
using CodeImp.DoomBuilder.Config;
|
2007-10-31 21:33:06 +00:00
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
2007-10-31 20:34:09 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Interface
|
|
|
|
{
|
|
|
|
public partial class ImageBrowser : UserControl
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
private const int ITEM_WIDTH = 80;
|
|
|
|
private const int ITEM_HEIGHT = 92;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
2007-10-31 21:33:06 +00:00
|
|
|
// Graphics device for rendering
|
|
|
|
private D3DDevice graphics;
|
|
|
|
|
|
|
|
// Items list
|
|
|
|
private List<ImageBrowserItem> items;
|
2007-10-31 20:34:09 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
2007-10-31 21:33:06 +00:00
|
|
|
public int Count { get { return items.Count; } }
|
|
|
|
|
2007-10-31 20:34:09 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public ImageBrowser()
|
|
|
|
{
|
2007-10-31 22:16:53 +00:00
|
|
|
// Initialize
|
|
|
|
InitializeComponent();
|
2007-10-31 21:33:06 +00:00
|
|
|
|
2007-10-31 20:34:09 +00:00
|
|
|
// Make items list
|
2007-10-31 21:33:06 +00:00
|
|
|
items = new List<ImageBrowserItem>();
|
2007-10-31 22:16:53 +00:00
|
|
|
|
|
|
|
rendertarget.SetBounds(0, 0, 0, 10000, BoundsSpecified.Height);
|
|
|
|
rendertarget.ClientSize = new Size(0, 10000);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
~ImageBrowser()
|
|
|
|
{
|
|
|
|
// Clean up
|
|
|
|
if(graphics != null) graphics.Dispose();
|
2007-10-31 20:34:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Events
|
|
|
|
|
|
|
|
// When resized
|
|
|
|
protected override void OnResize(EventArgs e)
|
|
|
|
{
|
2007-10-31 21:33:06 +00:00
|
|
|
// Redraw
|
|
|
|
Redraw();
|
2007-10-31 20:34:09 +00:00
|
|
|
|
|
|
|
// Call base
|
|
|
|
base.OnResize(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2007-10-31 21:33:06 +00:00
|
|
|
#region ================== Rendering
|
|
|
|
|
2007-10-31 22:16:53 +00:00
|
|
|
// Initialize
|
|
|
|
public void InitializeGraphics()
|
|
|
|
{
|
|
|
|
// Make graphics device
|
|
|
|
graphics = new D3DDevice(rendertarget);
|
|
|
|
graphics.Initialize();
|
|
|
|
}
|
|
|
|
|
2007-10-31 21:33:06 +00:00
|
|
|
// This redraws the list
|
|
|
|
public void Redraw()
|
|
|
|
{
|
|
|
|
int numitemswide;
|
2007-10-31 20:34:09 +00:00
|
|
|
|
2007-10-31 21:33:06 +00:00
|
|
|
// Calculate number of items wide
|
|
|
|
numitemswide = (int)Math.Floor((float)ClientSize.Width / (float)ITEM_WIDTH);
|
|
|
|
}
|
|
|
|
|
2007-10-31 20:34:09 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// This adds an item
|
2007-10-31 21:33:06 +00:00
|
|
|
public void Add(string text, ImageData image, object tag)
|
2007-10-31 20:34:09 +00:00
|
|
|
{
|
2007-10-31 21:33:06 +00:00
|
|
|
ImageBrowserItem i;
|
|
|
|
|
2007-10-31 20:34:09 +00:00
|
|
|
// Make new item
|
2007-10-31 21:33:06 +00:00
|
|
|
i = new ImageBrowserItem(text, image, tag);
|
2007-10-31 20:34:09 +00:00
|
|
|
|
|
|
|
// Add item to list
|
2007-10-31 21:33:06 +00:00
|
|
|
items.Add(i);
|
2007-10-31 20:34:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|