Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 1.53 KB  |  hits: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to use Gdk# library in C# (mono)?
  2. GDKEXAMPLE(){
  3.     win = new Gtk.Window ("Gdk nightmare");
  4.     win.SetDefaultSize (400, 300);
  5.     img=new Gtk.Image();
  6.     Drawable dr=new Drawable(null); //how to instantiate this object?
  7.     Gdk.GC gc=new Gdk.GC(null); //how to instantiate this object?
  8.     Point[] pts=new Point[3];
  9.     pts[0]=new Point(10,10);
  10.     pts[1]=new Point(15,20);
  11.     pts[2]=new Point(20,50);
  12.  
  13.     dr.DrawLines(gc,pts);
  14.     Pixmap pxmp=new Pixmap(dr,100,100);
  15.     img.SetFromPixmap(pxmp,pxmp); //Requests a pixmap and pixmap mask: what mask?
  16.     img.QueueDraw();
  17.  
  18.     win.Add(img);
  19.     win.ShowAll();
  20. }
  21.        
  22. class GdkApp : Gtk.Window {
  23. Pixmap pxp;
  24. public static void Main()
  25. {
  26.     Application.Init();
  27.     new GdkApp();
  28.     Application.Run();
  29. }
  30.  
  31. public GdkApp() : base("Simple drawing")
  32. {
  33.     SetDefaultSize(230, 150);
  34.     DeleteEvent+=delegate {Application.Quit(); };
  35.     base.KeyPressEvent+= OnKeyPress;
  36.     ShowAll();
  37. }
  38. void OnKeyPress(object sender, KeyPressEventArgs KPargs)
  39. {
  40.     Gdk.GC gc=new Gdk.GC((Drawable)base.GdkWindow);
  41.     gc.RgbFgColor=new Gdk.Color(255,50,50);
  42.     gc.RgbBgColor=new Gdk.Color(0,0,0);
  43.     gc.SetLineAttributes(3,LineStyle.OnOffDash,CapStyle.Projecting,JoinStyle.Round);
  44.  
  45.     Gdk.Point[] pts=new Gdk.Point[8];
  46.     pts[0]=new Gdk.Point(10,50);
  47.     pts[1]=new Gdk.Point(15,70);
  48.     pts[2]=new Gdk.Point(20,80);
  49.     pts[3]=new Gdk.Point(25,70);
  50.     pts[4]=new Gdk.Point(30,80);
  51.     pts[5]=new Gdk.Point(40,90);
  52.     pts[6]=new Gdk.Point(55,85);
  53.     pts[7]=new Gdk.Point(75,65);
  54.  
  55.     base.GdkWindow.DrawLines(gc,pts);
  56. }
  57. }