0
votes

I install MonoDevelop, GTK# and stuff. I open some Cairo tutorials (following the advice given here). I create a new GTK# project in MonoDevelop and add the Cairo library to the references. Using this tutorial, I create an expose event for a DrawingArea in a simple GTK form. Code is the following:

protected void OnDrawingAreaExposed (object obj, Gtk.ExposeEventArgs args)
{
    DrawingArea drawArea = (DrawingArea)obj;
    Cairo.Context ctx = Gdk.CairoHelper.Create(drawArea.GdkWindow);

    PointD p1,p2,p3,p4;

    p1 = new PointD (10,10);
    p2 = new PointD(100,100);

    ctx.MoveTo(p1);
    ctx.LineTo(p2);

    ((IDisposable)ctx).Dispose();
}

Whe running the app, nothing is drawn. Ok, I assume that cairo lib is not installed in system. I download it from GTK+ page, put in to folder, where project executable lies - and BANG! - app crashes (System.DllNotFoundException). In result of all of the above I have a question - is it possible for one to use Cairo in Mono apps on Winows?

P.S. Will add error window screenshot later, if it's of any help.

2
It is definately possible yes, I've used Mono.Cairo with Gtk# on windows for a while now. What is the full exception?IanNorton
@IanNorton actually, it was all my mistake, as explained in answer.Arnthor
@IanNorton BTW, were you having the same problems as a Mono developer?Arnthor
yes, my app runs on linux and windowsIanNorton

2 Answers

1
votes

You shouldn't try to copy that compiled cairo libraries into the bin folder. Mono (or MonoDevelop - not sure of this part) is shipped with the libs needed. You just add them via clicking on References folder and then Edit References (similar to that of Visual Studio).

Problem is in the GTK UI editor of MonoDevelop. There is no option to add a custom widget there, though I believe this to be a common task. If you want to do so, you will have to hack on file, generated by that editor (file, named as your window class, in gtk-gui folder). Say, if you have a CairoCanvas class, which inherits the Gtk.DrawingArea widget class - you just find the line, like this.drawingarea1 = new global::Gtk.DrawingArea() and change it to this.drawingarea1 = new CairoCanvas(), not forgetting to add a using YourProjectName; directive upwards, of course. Every time you change something in your GUI, file will be regenerated. So then you go to that file, see that waring that it's changed, press the "Keep changes" button to preserve your work. Then rebuild your project once more, and that's it.

I gladly hope this answer will help some Mono newcomers. And I hope to celebrate the day, when MonoDevelop community (it's OSS, isn't it?) will implement that lacking functionality.

1
votes

I think you're missing some steps.

Try to add this between ctx.LineTo(p2); and ((IDisposable)ctx).Dispose(); :

// give a color to line (red in this case)
ctx.Color = new Color (1,0,0);
// this is line type
ctx.Stroke ();

((IDisposable) ctx.Target).Dispose ();