using System;
+using System.Timers;
using Cairo;
using Pango;
+using Gdk;
using Gtk;
public class TextDisplay : DrawingArea, IKeyPress {
private TextDocument doc = null;
- private Font font;
+ private Pango.Font font;
// FIXME: Proportional fonts?
- private float fontwidth;
- private float fontheight;
+ private float fontWidth;
+ private float fontHeight;
+
+ private Timer helpTimer;
+ private HelpBox controlHelp;
+ private bool showHelp;
public TextDisplay() {
FontDescription fd = Pango.FontDescription.FromString("Courier 12");
font = this.PangoContext.LoadFont(fd);
FontMetrics fm = font.GetMetrics(null);
- fontheight = Pango.Units.ToPixels(fm.Ascent + fm.Descent);
- fontwidth = fontheight * 0.5333f;
- Console.WriteLine("Using {0} {1}pt ({2}x{3}px)", fd.Family, fd.Size, fontwidth, fontheight);
+ fontHeight = Pango.Units.ToPixels(fm.Ascent + fm.Descent);
+ fontWidth = fontHeight * 0.5333f;
+ Console.WriteLine("Using {0} {1}pt ({2}x{3}px)", fd.Family, fd.Size, fontWidth, fontHeight);
+
+ controlHelp = new HelpBox(this.PangoContext, "control_help");
ModifyBg(StateType.Normal, new Gdk.Color(0xFF, 0xFF, 0xFF));
}
gr.MoveTo(0, 0);
Pango.CairoHelper.ShowLayout(gr, layout);
- gr.Operator = Operator.Xor;
+ gr.SetSourceRGB(0.0, 0.0, 0.0);
gr.NewPath();
- gr.Rectangle((doc.cursor.x - doc.textorigin.x)*fontwidth, (doc.cursor.y - doc.textorigin.y)*fontheight, fontwidth, fontheight);
+ gr.Rectangle((doc.cursor.x - doc.textorigin.x)*fontWidth, (doc.cursor.y - doc.textorigin.y)*fontHeight, fontWidth, fontHeight);
gr.Fill();
+
+ if (showHelp) {
+ controlHelp.draw(gr, width, height);
+ }
}
- protected override bool OnExposeEvent(Gdk.EventExpose args)
- {
+ protected override bool OnExposeEvent(Gdk.EventExpose args) {
Gdk.Window win = args.Window;
#if OLD_SYSTEMS
protected override void OnSizeAllocated(Gdk.Rectangle r) {
base.OnSizeAllocated(r);
if (doc != null)
- doc.SetPageSize((int)(r.Width / fontwidth) - 1, (int)(r.Height / fontheight) - 1);
+ doc.SetPageSize((int)(r.Width / fontWidth) - 1, (int)(r.Height / fontHeight) - 1);
}
public void Update() {
QueueDraw();
}
+ public void ShowHelp() {
+ showHelp = true;
+ helpTimer = null;
+ QueueDraw();
+ }
+
+ public void HideHelp() {
+ if (helpTimer != null) {
+ helpTimer.Stop();
+ helpTimer = null;
+ }
+ if (showHelp)
+ showHelp = false;
+ QueueDraw();
+ }
[GLib.ConnectBefore ()]
public void KeyPress(object o, KeyPressEventArgs args) {
if (doc == null) return;
+ if ((args.Event.State & ModifierType.ControlMask) != 0) {
+ switch(args.Event.Key) {
+ default:
+ HideHelp();
+ break;
+ }
+ } else {
+ switch(args.Event.Key) {
+ case Gdk.Key.Control_L:
+ case Gdk.Key.Control_R:
+ helpTimer = new Timer();
+ helpTimer.Elapsed += delegate(object o2, ElapsedEventArgs e) {
+ ShowHelp();
+ };
+ helpTimer.AutoReset = false;
+ helpTimer.Interval = 1000;
+ helpTimer.Start();
+ break;
+ }
+ }
doc.KeyPress(o, args);
}
+
+ public void KeyRelease(object o, KeyReleaseEventArgs e) {
+ switch(e.Event.Key) {
+ case Gdk.Key.Control_L:
+ case Gdk.Key.Control_R:
+ HideHelp();
+ break;
+ }
+ }
}