GtkSharp/sample/DrawingSample.cs
Dan Winship 62258ca7c3 * generator/CallbackGen.cs:
* generator/CodeGenerator.cs: 
        * generator/ManagedCallString.cs:
        * generator/Property.cs: Remove unused vars

        * generator/Method.cs (GetHashCode): have to implement this since
        we're overriding Equals.

        * generator/CallbackGen.cs: print a message when generating a
        broken struct-returning callback. (Currently affects
        GtkSharp.TextSegSplitFuncNative and
        GtkSharp.TextSegCleanupFuncNative)

        * gdk/glue/device.c: 
        * gdk/glue/dragcontext.c: Add missing prototypes

        * gtk/Gtk.metadata: Mark SeparatorToolItem.Draw "new". Re-rename
        CheckMenuItem.Toggled to EmitToggled rather than Toggle, since
        that's a better description of what it does.

        * gtk/CheckMenuItem.custom: implement a "Toggle" method that does
        what the documentation claims it does.

        * gtk/NodeStore.cs: remove unused var

        * gnome/Gnome.metadata: mark DateEdit.Flags, Dialog.Default, and
        PropertyBox.State "new". Hide GnomePixmapEntry.GnomeEntry and
        GnomePixmapEntry.GtkEntry since they do exactly the same thing as
        the methods of the same names inherited from GnomeFileEntry.

        * gnome/glue/canvas-proxy.c:
        * gnome/glue/canvas-proxy.h:
        * gnome/glue/canvas-proxy-marshal.c:
        * gnome/glue/canvas-proxy-marshal.h:
        * gnome/glue/canvas-proxy-marshal.list: Remove unused code

        * gnome/glue/Makefile.am (libgnomesharpglue_2_la_SOURCES): update

        * panelapplet/PanelApplet.metadata: mark PanelApplet.Flags "new"

        * sample/CanvasExample.cs: 
        * sample/CustomCellRenderer.cs: 
        * sample/CustomNotebook.cs: 
        * sample/DrawingSample.cs:
        * sample/Fifteen.cs: 
        * sample/GladeTest.cs: 
        * sample/GtkDemo/DemoHyperText.cs: 
        * sample/GtkDemo/DemoPixbuf.cs: 
        * sample/ScribbleXInput.cs: remove unused vars, use
        GLib.Timeout.Add rather than the deprecated Gtk.Timeout.Add

svn path=/trunk/gtk-sharp/; revision=38043
2004-12-21 18:46:42 +00:00

123 lines
2.3 KiB
C#

//
// Sample program demostrating using Cairo with Gtk#
//
using Gtk;
using System;
using System.Drawing;
class X {
static DrawingArea a, b;
static void Main ()
{
Application.Init ();
Gtk.Window w = new Gtk.Window ("System.Drawing and Gtk#");
// Custom widget sample
a = new PrettyGraphic ();
// Event-based drawing
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 (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)
{
rect = args.Allocation;
}
static void ExposeHandler (object obj, ExposeEventArgs args)
{
Gdk.EventExpose ev = args.Event;
Gdk.Window window = ev.Window;
using (Graphics g = Gdk.Graphics.FromDrawable (window)){
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);
}
}
}
}
//
// A sample using inheritance to draw
//
class PrettyGraphic : DrawingArea {
public PrettyGraphic ()
{
SetSizeRequest (200, 200);
}
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
using (Graphics g = Gdk.Graphics.FromDrawable (args.Window)){
Pen p = new Pen (Color.Blue, 1.0f);
for (int i = 0; i < 600; i += 60)
for (int j = 0; j < 600; j += 60)
g.DrawLine (p, i, 0, 0, j);
}
return true;
}
}
class MovingText : DrawingArea {
static int d = 0;
Font f;
public MovingText ()
{
GLib.Timeout.Add (20, new GLib.TimeoutHandler (Forever));
SetSizeRequest (300, 200);
f = new Font ("Times", 20);
}
bool Forever ()
{
QueueDraw ();
return true;
}
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
using (Graphics g = Gdk.Graphics.FromDrawable (args.Window)){
using (Brush back = new SolidBrush (Color.White),
fore = new SolidBrush (Color.Red)){
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;
}
}