• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Java-Cocoa drawing -- help!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Java-Cocoa drawing -- help!


  • Subject: Re: Java-Cocoa drawing -- help!
  • From: Shawn Erickson <email@hidden>
  • Date: Mon, 12 Apr 2004 08:13:55 -0700

I would also study up on drawing environment Cocoa provides [1], drawRect isn't about drawing a rectangle it is about doing the drawing needed for the view. The rectangle you get supplied lets you know the largest bounding box of he area that needs updating (the union of all current invalidated rects for this view, which are setup by setNeedsDisplay calls, etc.). Ideally you should limit your drawing to just what is asked. If you don't you are just wasting time since things are already clipped to the supplied rect and anything outside of that is just wasted drawing.

Additionally as of Mac OS X 10.3 you can get at the actual (near actual, overlapping rects are unioned) rect list that needs drawing so you can further tune your drawing. These are provided by rectsBeingDrawn or needsToDrawRect.

-Shawn

[1] <http://developer.apple.com/documentation/Cocoa/Conceptual/DrawViews/ index.html>

On Apr 12, 2004, at 7:29 AM, Moray Taylor wrote:

Jim,

From your code snippets, it doesn't look like you have subclassed NSView, you will need to do this before you can do custom drawing in an NSView.

Once you have subclassed the view, you need to override the drawRect method with something like this...

public void drawRect(NSRect rect) {
NSRect nr = new NSRect(0,0,40,40);

NSBezierPath BP = NSBezierPath.bezierPath();
NSColor.colorWithCalibratedRGB(1f, 0f, 0f, 0.5f).set();
BP.fillRect(nr);

}

This will draw a transparent red rectangle in your view.

Let me know if you need any more info.

Cheers

Moray

In IB, I have created a window with a NSview, and have called it myview:

public NSView myview;

Now, how do I draw a simple rectangle using NSRect to this NSview?

I hoped that something like...

nr = new NSrect(0,0,40,40);
myview.drawRect(nr);

...would do it, but no. It compiles without error or warning -- yet
does nothing. What is the proper way to draw to a NSView?

Jim
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Java-Cocoa drawing -- help! (From: James Burton <email@hidden>)
 >Re: Java-Cocoa drawing -- help! (From: Moray Taylor <email@hidden>)

  • Prev by Date: Re: Java-Cocoa drawing -- help!
  • Next by Date: Re: Passing C Style Function Callbacks in Cocoa
  • Previous by thread: Re: Java-Cocoa drawing -- help!
  • Next by thread: Re: Java-Cocoa drawing -- help!
  • Index(es):
    • Date
    • Thread