Drawing to a View in CocoaSharp

12 views
Skip to first unread message

rob.m...@gmail.com

unread,
Sep 21, 2007, 1:56:43 PM9/21/07
to cocoa-sharp-dev
I'm having a problem with drawing in a View. What happens is that
whenever I try to call Graphics.GetHwnd(this.NativeReference) I get a
very long winded BAD_EXEC_ACCESS error or something along those
lines. If anyone has any experience using the Graphics object in a
View context let me know. If asked I can provide an error printout,
just not this second.

The BezierPath.FillRect method call works just fine. I'm assuming
because it's just a simple wrapper over the NSBezierPath cocoa class.
But there doesn't seem to be very much in the way of extended Cocoa
drawing calls in Cocoa#. Stuff like NSFillRect.

BTW the code was taken directly from the View demo included in the
latest release of Cocoa#.

Any help and suggestions would be much appreciated. Thanks again.

Robert

breeve

unread,
Oct 3, 2007, 3:42:15 PM10/3/07
to cocoa-sharp-dev
I have tried running the View demo as well. I couldn't get them to
run. They are using System.Drawing which currently requires X.
Ironically, it wouldn't run under X either. The other examples ran.

I think the bigger question is how to do Quartz drawing from Cocoa #.
I don't see anything equivalent to NSGraphicsContext in Cocoa#. Am I
missing something obvious?

Brock

On Sep 21, 12:56 pm, "rob.mch...@gmail.com" <rob.mch...@gmail.com>
wrote:

rob.m...@gmail.com

unread,
Oct 4, 2007, 11:36:07 AM10/4/07
to cocoa-sharp-dev
I would concur. But I'm only superficially familiar with the project.

I took the assumption that the System.Drawing routines were modified
so they could draw to an NSView. But this is probably incorrect.

I like C# as a language but it would seem that I am unable to use
Cocoa# for development if I can't do drawing to quartz.

I did have one other question. Is there an objective-c helper class
that allows one to make calls into the Mono runtime. Something that
would allow me to create a Proxy object in objective c. Something
that would forward my message sends to the mono class instance.
Possibly by doing some kind of message translation routines or lookup?

breeve

unread,
Oct 9, 2007, 1:59:35 PM10/9/07
to cocoa-sharp-dev
Ok. I dug in deeper. You can draw via the BezierPath class. I added a
constructor and methods to the BezierPath below:

public BezierPath() : base()
{
}

public void MoveToPoint(Point point)
{
ObjCMessaging.objc_msgSend(NativeObject, "moveToPoint:",
typeof(void), typeof(Point), point);
}

public void LineToPoint(Point point)
{
ObjCMessaging.objc_msgSend(NativeObject, "lineToPoint:",
typeof(void), typeof(Point), point);
}

public void Stroke()
{
ObjCMessaging.objc_msgSend(NativeObject, "stroke",
typeof(void));
}


Now you can do something inside the Draw of one of the samples like:

Color.Black.Set();
BezierPath.FillRect(aRect);
Color.Red.Set();
BezierPath path = new BezierPath();
path.MoveToPoint(new Point(3,3));
path.LineToPoint(new Point(50,50));
path.Stroke();

-- Brock

On Oct 4, 10:36 am, "rob.mch...@gmail.com" <rob.mch...@gmail.com>
wrote:

> > > Robert- Hide quoted text -
>
> - Show quoted text -

Tizzo

unread,
Nov 1, 2007, 2:04:46 PM11/1/07
to cocoa-sharp-dev
I'm looking at the BezierPath class and it appears that you guys might
not be looking at the latest revision of the library. See the
following link:

http://anonsvn.mono-project.com/viewcvs/trunk/cocoa-sharp/src/Cocoa/BezierPath.cs?diff_format=h&view=markup

This class already has a default constructor and etc.

Breeve, if you have some updates to this file. Let me know and I can
add them. I could probably just take what you have here in this post.

breeve

unread,
Nov 2, 2007, 10:53:10 AM11/2/07
to cocoa-sharp-dev
I have the latest source and the BezierPath class does not have a
default constructor. If a class doesn't have a constructor the C#
compiler will create a default one for you. If you define a
constructor csc will not create a default constructor. Since
BezierPath defined a constructor, a default constructor was not
automatically generated so I added one. For example:

B b = new B(); //does not work.

private class A
{
public A()
{
}

public A(int a)
{
}
}

private class B : A
{
public B(int a)
: base(a)
{
}
}

I am not a Cocoa expert by any means. I am just playing around with
the API and noticed there wasn't a lot of drawing functionality
exposed. I am not familiar with the process for contributing to open
source projects. Do you need a patch file? My changes are what I
posted.

Thanks,

Brock

On Nov 1, 1:04 pm, Tizzo <schav...@gmail.com> wrote:
> I'm looking at the BezierPath class and it appears that you guys might
> not be looking at the latest revision of the library. See the
> following link:
>

> http://anonsvn.mono-project.com/viewcvs/trunk/cocoa-sharp/src/Cocoa/B...

> > > - Show quoted text -- Hide quoted text -

Reply all
Reply to author
Forward
0 new messages