Add some lovin'

svn path=/trunk/gtk-sharp/; revision=28385
This commit is contained in:
Miguel de Icaza 2004-05-28 19:38:23 +00:00
parent 977c36bd98
commit ebff0837aa
2 changed files with 56 additions and 9 deletions

View File

@ -11,7 +11,7 @@ class X {
static void Main ()
{
Application.Init ();
Gtk.Window w = new Gtk.Window ("Hello");
Gtk.Window w = new Gtk.Window ("System.Drawing and Gtk#");
// Custom widget sample
a = new PrettyGraphic ();
@ -20,16 +20,28 @@ class X {
b = new DrawingArea ();
b.ExposeEvent += ExposeHandler;
b.SizeAllocated += SizeAllocatedHandler;
Button c = new Button ("Quit");
c.Clicked += quit;
MovingText m = new MovingText ();
Box box = new HBox (true, 0);
box.Add (a);
//box.Add (b);
box.Add (b);
box.Add (m);
box.Add (c);
w.Add (box);
w.ShowAll ();
Application.Run ();
}
static void quit (object obj, EventArgs args)
{
Application.Quit ();
}
static Gdk.Rectangle rect;
static void SizeAllocatedHandler (object obj, SizeAllocatedArgs args)
@ -43,7 +55,6 @@ class X {
Gdk.Window window = ev.Window;
using (Graphics g = Gdk.Graphics.FromDrawable (window)){
Console.WriteLine ("{0} and {1}", -ev.Area.X, -ev.Area.Y);
g.TranslateTransform (ev.Area.X, ev.Area.Y);
using (Pen p = new Pen (Color.Red)){
g.DrawPie (p, 0, 0, rect.Width, rect.Height, 50, 90);
@ -57,6 +68,11 @@ class X {
//
class PrettyGraphic : DrawingArea {
public PrettyGraphic ()
{
SetSizeRequest (200, 200);
}
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
Gdk.Window win = args.Window;
@ -66,12 +82,7 @@ class PrettyGraphic : DrawingArea {
//Console.WriteLine ("{0} and {1}", -args.Area.X, -args.Area.Y);
//g.TranslateTransform (-args.Area.X, -args.Area.Y);
Pen p = new Pen (Color.Blue, 1.0f);
Pen q = new Pen (Color.Red, 1.0f);
g.DrawLine (p, 0, 0, 100, 100);
g.DrawLine (q, 0, 0, 100, 100);
return true;
for (int i = 0; i < 600; i += 60)
for (int j = 0; j < 600; j += 60)
g.DrawLine (p, i, 0, 0, j);
@ -79,3 +90,40 @@ class PrettyGraphic : DrawingArea {
return true;
}
}
class MovingText : DrawingArea {
static int d = 0;
public MovingText ()
{
Gtk.Timeout.Add (50, new Function (Forever));
SetSizeRequest (300, 200);
}
bool Forever ()
{
QueueDraw ();
return true;
}
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
Gdk.Window win = args.Window;
Gdk.Rectangle area = args.Area;
using (Graphics g = Gdk.Graphics.FromDrawable (args.Window)){
Brush back = new SolidBrush (Color.White);
Brush fore = new SolidBrush (Color.Red);
Font f = new Font ("Times", 20);
g.FillRectangle (back, 0, 0, 400, 400);
g.TranslateTransform (150, 100);
g.RotateTransform (d);
d += 3;
g.DrawString ("Mono", f, fore, 0, 0);
}
return true;
}
}

View File

@ -42,7 +42,6 @@ namespace Gdk {
object r = mi.Invoke (null, args);
System.Drawing.Graphics g = (System.Drawing.Graphics) r;
Console.WriteLine ("-> {0} / {1}", x_off, y_off);
g.TranslateTransform (-x_off, -y_off);
return g;