1 using System.Collections;
7 public struct HelpItem {
11 public HelpItem(string key, string text) {
16 public override string ToString() {
17 return "<b>" + Key + "</b>\t" + Text;
21 public class HelpBox {
22 private Pango.Context pc;
23 private Pango.FontDescription titleFont;
24 private Pango.FontDescription textFont;
25 private string helpTitle;
26 private HelpItem[] helpText;
27 private int Width = 480;
28 private int Height = 360;
29 private int Columns = 3;
31 public HelpBox(Pango.Context pc, string title, HelpItem[] items) {
38 public HelpBox(Pango.Context pc, string filename) {
39 StreamReader file = new StreamReader(filename);
41 ArrayList items = new ArrayList();
44 helpTitle = file.ReadLine();
45 while ((line = file.ReadLine()) != null) {
46 string[] i = line.Split(null, 2);
48 items.Add(new HelpItem(i[0], i[1]));
51 helpText = new HelpItem[items.Count];
52 for (int i = 0; i < items.Count; i++) {
53 helpText[i] = (HelpItem) items[i];
59 titleFont = Pango.FontDescription.FromString("Helvetica Bold 24");
60 textFont = Pango.FontDescription.FromString("Helvetica 16");
61 Pango.FontMetrics fmTitle = pc.GetMetrics(titleFont, null);
62 Pango.FontMetrics fmText = pc.GetMetrics(textFont, null);
63 int hTitle = Pango.Units.ToPixels(fmTitle.Ascent + fmTitle.Descent);
64 int hText = Pango.Units.ToPixels(fmText.Ascent + fmText.Descent);
67 for (int i = 0; i < helpText.Length; i++) {
68 Pango.Layout layout = new Pango.Layout(pc);
69 Pango.Rectangle r, r2;
71 layout.FontDescription = textFont;
72 layout.SetMarkup(helpText[i].ToString());
73 layout.GetExtents(out r, out r2);
74 int pw = Pango.Units.ToPixels(r2.Width);
75 if ((pw + 8) * Columns > Width) {
76 Width = (pw + 8) * Columns;
79 Height = hTitle + (helpText.Length / 3 + 1) * hText + 12;
82 public void draw(Cairo.Context gr, int width, int height) {
84 Cairo.Rectangle r = new Cairo.Rectangle(
85 width / 2 - Width / 2,
86 height / 2 - Height / 2,
89 gr.SetSourceRGBA(1.0, 1.0, 1.0, 0.8);
94 gr.SetSourceRGB(0.0, 0.0, 0.0);
99 gr.MoveTo(r.X + 4, r.Y + 4);
100 layout = new Pango.Layout(pc);
101 layout.SetText(helpTitle);
102 layout.Width = Pango.Units.FromPixels((int)r.Width);
103 layout.FontDescription = titleFont;
104 Pango.CairoHelper.ShowLayout(gr, layout);
107 int ColumnWidth = Width / Columns;
108 int ColumnLines = helpText.Length / Columns + 1;
109 for (int i = 0; i < Columns; i++) {
110 gr.MoveTo(r.X + 4 + (i * ColumnWidth), r.Y + 38);
112 for (int j = 0; j < ColumnLines && ii < helpText.Length; j++) {
113 column += helpText[ii].ToString() + "\n";
116 layout = new Pango.Layout(pc);
117 layout.SetMarkup(column);
118 layout.Width = Pango.Units.FromPixels(ColumnWidth);
119 layout.FontDescription = textFont;
120 Pango.CairoHelper.ShowLayout(gr, layout);