So, after a lot of patience, I eventually found the answer to the question of how to get started with Gdk #.
In principle, only events can trigger a drawing. I tried calling the drawings directly from the methods, but this did not work. Here is the base code that I was missing in C #:
using System; using Gdk; using Gtk; class GdkApp : Gtk.Window { public static void Main() { Application.Init(); new GdkApp(); Application.Run(); } public GdkApp() : base("Simple drawing") { SetDefaultSize(230, 150); DeleteEvent+=delegate {Application.Quit(); }; ShowAll(); } protected override bool OnExposeEvent (EventExpose evnt) { bool ok = base.OnExposeEvent (evnt); draw (); return ok; } void draw() { Gdk.GC gc = new Gdk.GC ((Drawable)base.GdkWindow); gc.RgbFgColor = new Gdk.Color (255, 50, 50); gc.RgbBgColor = new Gdk.Color (0, 0, 0); gc.SetLineAttributes (3, LineStyle.OnOffDash, CapStyle.Projecting, JoinStyle.Round); Gdk.Point[] pts = new Gdk.Point[8]; pts [0] = new Gdk.Point (10, 50); pts [1] = new Gdk.Point (15, 70); pts [2] = new Gdk.Point (20, 80); pts [3] = new Gdk.Point (25, 70); pts [4] = new Gdk.Point (30, 80); pts [5] = new Gdk.Point (40, 90); pts [6] = new Gdk.Point (55, 85); pts [7] = new Gdk.Point (75, 65); base.GdkWindow.DrawLines (gc, pts); } }
Here we create the main window and record the entire drawing in the OnExposeEvent method. This method is called when any widget must (in whole or in part) be redrawn. There you need to create an instance of the Gdk.GC object (context) using the "Drawable" parameter. Not much choice: Gdk.Pixmap or Gdk.Window. I chose Gdk.Window, as it was the easiest surface. You can then customize the context object to decide how it will be drawn.
Finally, and directly from the Drawable object that you want to draw, you can call the drawing methods: here I just wanted to build a series of 8 connected points.
Hope this helps some other users understand the logic of this gdk # namespace.
source share