/usr/share/gtk-sharp2-examples/DrawingSample.cs is in gtk-sharp2-examples 2.12.40-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | //
// Sample program demostrating using System.Drawing 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 += new ExposeEventHandler (ExposeHandler);
b.SizeAllocated += new SizeAllocatedHandler (SizeAllocatedHandler);
Button c = new Button ("Quit");
c.Clicked += new EventHandler (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 = Gtk.DotNet.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 = Gtk.DotNet.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 = Gtk.DotNet.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;
}
}
|