/*=============================================================================
Project: SharpImage
Module: siFormAddLabel.cs
Language: C#
Author: Dan Mueller
Date: $Date: 2007-07-06 10:57:00 +1000 (Fri, 06 Jul 2007) $
Revision: $Revision: 2 $
Copyright (c) Queensland University of Technology (QUT) 2007.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=============================================================================*/
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;
using SharpImage.Main;
using SharpImage.Rendering;
namespace SharpImage.Forms
{
public partial class siFormAddLabel : siFormTool
{
#region Label Info Classes
//=====================================================================
public abstract class siLabelInfo
{
protected itk.itkPixelType m_PixelType;
public siLabelInfo(itk.itkPixelType type)
{
this.m_PixelType = type;
}
public abstract String Name { get; }
public override string ToString()
{
return this.Name;
}
}
public class siLabelInfoSingle : siLabelInfo
{
private Color m_RGB = Color.Red;
private Byte m_Alpha = 128;
private itk.itkPixel m_Value;
public siLabelInfoSingle(itk.itkPixelType type)
: base(type)
{
this.m_Value = new itk.itkPixel(type, 255);
}
[Browsable(false)]
public override String Name
{
get { return "Single Color"; }
}
[Browsable(true)]
[Category("Single Color")]
[ParenthesizePropertyName(false)]
[RefreshProperties(RefreshProperties.All)]
public Color RGB
{
get { return this.m_RGB; }
set { this.m_RGB = Color.FromArgb(value.R, value.G, value.B); }
}
[Browsable(true)]
[Category("Single Color")]
[ParenthesizePropertyName(false)]
[RefreshProperties(RefreshProperties.All)]
public Byte Alpha
{
get { return this.m_Alpha; }
set { this.m_Alpha = value; }
}
[Browsable(false)]
public Color Color
{
get { return Color.FromArgb(m_Alpha, this.m_RGB); }
}
[Browsable(true)]
[Category("Single Color")]
[ParenthesizePropertyName(false)]
[RefreshProperties(RefreshProperties.All)]
[TypeConverter(typeof(itkPixelTypeConverter))]
public itk.itkPixel Value
{
get { return this.m_Value; }
set { this.m_Value = value; }
}
}
public class siLabelInfoRandom : siLabelInfo
{
private Byte m_Alpha = 128;
public siLabelInfoRandom(itk.itkPixelType type)
: base(type)
{
}
[Browsable(false)]
public override String Name
{
get { return "Random Colors"; }
}
[Browsable(true)]
[Category("Random Colors")]
[ParenthesizePropertyName(false)]
[RefreshProperties(RefreshProperties.All)]
public Byte Alpha
{
get { return this.m_Alpha; }
set { this.m_Alpha = value; }
}
}
//=====================================================================
#endregion
#region Construction and Disposal
//=====================================================================
///
/// Constructor
///
///
public siFormAddLabel(IApplication parent, itk.itkPixelType pixelType)
: base()
{
// Init GUI
InitializeComponent();
this.Resize += new EventHandler(siFormAddLabel_Resize);
// Set member variables
this.m_PixelType = pixelType;
// Setup LabelInfo
this.comboType.Items.Add(new siLabelInfoSingle(this.PixelType));
this.comboType.Items.Add(new siLabelInfoRandom(this.PixelType));
this.comboType.SelectedIndex = 0;
this.comboType.SelectedIndexChanged += new EventHandler(comboType_SelectedIndexChanged);
this.m_LabelInfo = this.comboType.Items[0] as siLabelInfo;
this.propertyGrid.SelectedObject = this.m_LabelInfo;
}
//=====================================================================
#endregion
#region Properties
//=====================================================================
#region PixelType
//=====================================================================
private itk.itkPixelType m_PixelType;
public itk.itkPixelType PixelType
{
get { return this.m_PixelType; }
}
//=====================================================================
#endregion
#region LabelInfo
//=====================================================================
private siLabelInfo m_LabelInfo;
public siLabelInfo LabelInfo
{
get { return this.m_LabelInfo; }
}
//=====================================================================
#endregion
//=====================================================================
#endregion
#region Private Methods
//=====================================================================
void siFormAddLabel_Resize(object sender, EventArgs e)
{
this.comboType.Refresh();
}
private void comboType_SelectedIndexChanged(object sender, EventArgs e)
{
this.m_LabelInfo = this.comboType.SelectedItem as siLabelInfo;
this.propertyGrid.SelectedObject = this.m_LabelInfo;
}
//=====================================================================
#endregion
}
}