annotate UI/StatColumnStyle.cs @ 70:a8667ab60362

Re #180: Add multiple mutex groups * Make WinForms UI handle multiple groups instead of assuming one
author IBBoard <dev@ibboard.co.uk>
date Sat, 26 Sep 2009 19:55:13 +0000
parents e04bea5b7b3d
children e749b748e7ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
1 // This file (StatColumnStyle.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard.
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
2 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
3 // 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.
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
4
27
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System.Drawing;
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using System.Text;
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using System.Windows.Forms;
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 using IBBoard.WarFoundry.API.Objects;
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10
40
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
11 namespace IBBoard.WarFoundry.GUI.WinForms.UI
27
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 {
64
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
13 class StatColumnStyle : DataGridColumnStyle
27
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 {
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight)
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 {
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 Object obj = GetColumnValueAtRow(source, rowNum);
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 Rectangle rect = bounds;
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 g.FillRectangle(backBrush, rect);
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 if (obj is Stat)
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 {
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 Stat stat = (Stat) obj;
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 StringFormat stringFormat = new StringFormat();
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 stringFormat.Alignment = (stat.ParentSlotName == "Name" ? StringAlignment.Near : StringAlignment.Center);
64
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
26 g.DrawString(stat.SlotValueString, GetFont(), foreBrush, rect, stringFormat);
27
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 }
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 else
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 {
64
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
30 g.DrawString(NullText, GetFont(), foreBrush, rect);
27
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 }
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 }
64
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
33
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
34 private Font GetFont()
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
35 {
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
36 return DataGridTableStyle.DataGrid.Font;
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
37 }
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
38
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
39 protected override void Abort(int rowNum)
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
40 {
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
41 // Do nothing - we don't allow editing
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
42 }
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
43
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
44 protected override bool Commit(CurrencyManager dataSource, int rowNum)
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
45 {
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
46 // Do nothing - we don't allow editing - but pretend we did
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
47 return true;
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
48 }
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
49
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
50 protected override void Edit(CurrencyManager source, int rowNum, Rectangle bounds, bool readOnly, string displayText, bool cellIsVisible)
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
51 {
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
52 // Do nothing - we don't allow editing
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
53 }
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
54
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
55 protected override int GetMinimumHeight()
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
56 {
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
57 return GetFont().Height;
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
58 }
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
59
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
60 protected override int GetPreferredHeight(Graphics g, object value)
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
61 {
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
62 return GetFont().Height;
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
63 }
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
64
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
65 protected override Size GetPreferredSize(Graphics g, object value)
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
66 {
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
67 Size size = new Size();
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
68
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
69 if (value is Stat)
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
70 {
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
71 SizeF stringSize = g.MeasureString(((Stat) value).SlotValueString, GetFont());
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
72 size.Height = (int) Math.Ceiling(stringSize.Height);
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
73 size.Width = (int) Math.Ceiling(stringSize.Width);
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
74 }
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
75
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
76 return size;
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
77 }
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
78
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
79 protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum)
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
80 {
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
81 Paint(g, bounds, source, rowNum, false);
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
82 }
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
83
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
84 protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, bool alignToRight)
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
85 {
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
86 Paint(g, bounds, source, rowNum, SystemBrushes.Window, SystemBrushes.WindowText, alignToRight);
e04bea5b7b3d Fixes #157: Stats show object class name when selected
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
87 }
27
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88 }
526fefefb16b Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89 }