using System;
namespace CrayzEdsGui.Base{
/// <summary>
/// Summary description for ListboxTextItem.
/// </summary>
public class ListboxTextItem : ListboxItem
{
#region Fields
/// <summary>
/// Font to use for text rendering.
/// </summary>
protected Font font = null;
/// <summary>
/// Colors to use when rendering text.
/// </summary>
protected ColorRect textColors;
#endregion
#region Properties
/// <summary>
/// Get/Set the font used for text rendering.
/// </summary>
public Font Font {
get {
// prefer out own font
if (font != null) {
return font;
}
// try our owner window's font setting (may be null if owner uses no existant default font)
else if (owner != null) {
return owner.Font;
}
// no owner, just use the default (which may be null anyway)
else {
return GuiSystem.Instance.DefaultFont;
}
}
set {
font = value;
}
}
/// <summary>
/// Get/Set the text colors for this ListboxItem.
/// </summary>
public ColorRect TextColors
{
get
{
return textColors;
}
set
{
textColors = value;
}
}
#endregion
#region Constructors
public ListboxTextItem() :
base(string.Empty)
{
textColors = new ColorRect(
new Color(1,1,1),
new Color(1,1,1),
new Color(1,1,1),
new Color(1,1,1)
);
}
public ListboxTextItem(string text) :
base(text)
{
textColors = new ColorRect(
new Color(1,1,1),
new Color(1,1,1),
new Color(1,1,1),
new Color(1,1,1)
);
}
public ListboxTextItem(string text, int itemID, object itemData, bool itemDisabled) :
base(text, itemID, itemData, itemDisabled)
{
textColors = new ColorRect(
new Color(1,1,1),
new Color(1,1,1),
new Color(1,1,1),
new Color(1,1,1)
);
}
#endregion
#region Methods
/// <summary>
/// Set the colors to use for the text.
/// </summary>
/// <param name="topLeft"></param>
/// <param name="topRight"></param>
/// <param name="bottomLeft"></param>
/// <param name="bottomRight"></param>
public void SetTextColors(Color topLeft, Color topRight, Color bottomLeft, Color bottomRight)
{
textColors = new ColorRect(topLeft, topRight, bottomLeft, bottomRight);
}
/// <summary>
/// Set the text color to be used.
/// </summary>
/// <param name="color"></param>
public void SetTextColors(Color color)
{
textColors = new ColorRect(color, color, color, color);
}
#endregion
#region Base Class Methods
#region Properties
/// <summary>
/// Return the pixel size of this ListboxItem.
/// </summary>
public override Size Size
{
get {
Size tmp = new Size(0,0);
Font fnt = Font;
if (fnt != null) {
tmp.height = fnt.LineSpacing;
tmp.width = fnt.GetTextExtent(itemText);
}
return tmp;
}
}
#endregion
#region Methods
/// <summary>
/// Perform rendering for this ListboxItem
/// </summary>
/// <param name="position">Vector3 object describing the upper-left corner of area that should be rendered in to for the draw operation.</param>
/// <param name="alpha">Alpha value to be used when rendering the item (between 0.0f and 1.0f).</param>
/// <param name="clipper">Rect object describing the clipping rectangle for the draw operation.</param>
public override void Draw(Vector3 position, float alpha, Rect clipper)
{
if (selected && (selectBrushImage != null)) {
selectBrushImage.Draw(clipper, GuiSystem.Instance.Renderer.GetZLayer(2), clipper, GetModulateAlphaColourRect(selectColors, alpha));
}
Font fnt = Font;
if (fnt != null) {
position.z = GuiSystem.Instance.Renderer.GetZLayer(3);
fnt.DrawText(itemText, position, clipper, GetModulateAlphaColourRect(textColors, alpha));
}
}
#endregion
#endregion
}
}
|