view UI/StatColumnStyle.cs @ 85:0bb9f40d44eb

Re #88: Complete initial WinForms UI * Add basic initial "about" box * Translations (below) Re #179: Make sure that translations are used throughout UI * Make all controls translatable * Supply translations for all controls Re #204: Use new limits in WinForms UI * Warn the user and cap the number if we try to go out of range for equipment
author IBBoard <dev@ibboard.co.uk>
date Sat, 31 Oct 2009 20:54:42 +0000
parents e749b748e7ea
children
line wrap: on
line source

// This file (StatColumnStyle.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard.
//
// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.

using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using IBBoard.WarFoundry.API.Objects;

namespace IBBoard.WarFoundry.GUI.WinForms.UI
{
	class StatColumnStyle : DataGridColumnStyle
	{
		protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight)
		{
			Object obj = GetColumnValueAtRow(source, rowNum);
			Rectangle rect = bounds;
			g.FillRectangle(backBrush, rect);

			if (obj is Stat)
			{
				Stat stat = (Stat) obj;
				StringFormat stringFormat = new StringFormat();
				stringFormat.Alignment = (stat.ParentSlotName == "name" ? StringAlignment.Near : StringAlignment.Center);//TODO: make "name" a constrant
				g.DrawString(stat.SlotValueString, GetFont(), foreBrush, rect, stringFormat);
			}
			else
			{
				g.DrawString(NullText, GetFont(), foreBrush, rect);
			}
		}

		private Font GetFont()
		{
			return DataGridTableStyle.DataGrid.Font;
		}

		protected override void Abort(int rowNum)
		{
			// Do nothing - we don't allow editing
		}

		protected override bool Commit(CurrencyManager dataSource, int rowNum)
		{
			// Do nothing - we don't allow editing - but pretend we did
			return true;
		}

		protected override void Edit(CurrencyManager source, int rowNum, Rectangle bounds, bool readOnly, string displayText, bool cellIsVisible)
		{
			// Do nothing - we don't allow editing
		}

		protected override int GetMinimumHeight()
		{
			return GetFont().Height;
		}

		protected override int GetPreferredHeight(Graphics g, object value)
		{
			return GetFont().Height;
		}

		protected override Size GetPreferredSize(Graphics g, object value)
		{
			Size size = new Size();

			if (value is Stat)
			{
				SizeF stringSize = g.MeasureString(((Stat) value).SlotValueString, GetFont());
				size.Height = (int) Math.Ceiling(stringSize.Height);
				size.Width = (int) Math.Ceiling(stringSize.Width);
			}

			return size;
		}

		protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum)
		{
			Paint(g, bounds, source, rowNum, false);
		}

		protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, bool alignToRight)
		{
			Paint(g, bounds, source, rowNum, SystemBrushes.Window, SystemBrushes.WindowText, alignToRight);
		}
	}
}