|
From: | Alexander Malmberg |
Subject: | Re: Drawing to screen - nothing appears? |
Date: | Sat, 20 Nov 2004 13:46:17 +0100 |
User-agent: | Mozilla Thunderbird 0.8 (X11/20040926) |
Steven Schlansker wrote:
I'm trying to port an application that I've developed on Mac OS X to GNUStep/Linux and GNUStep/Windows. I'm currently running Gentoo with gnustep-base/gnustep-base-1.10.2_pre20041116 gnustep-base/gnustep-back-xlib-0.9.5_pre20041116 gnustep-base/gnustep-gui-0.9.5_pre20041116I'm using the libart backend, but xlib doesn't work either. The method I use for drawing goes like this: [NSWindow lockFocus] [NSColor set] NSRectFill (to clear the screen) for() [NSColor set] NSRectFill (to draw object) [NSWindow unlockFocus] [NSGraphicsContext flushGraphics]
Out of curiosity, could you provide some "real" example code that shows this? I'm not sure how to read the above pseudo-code (e.g. NSWindow has neither a +lockFocus method nor, if you mean an NSWindow instance, a -lockFocus method, so you should simply get an exception for that).
Anyway, the best way of drawing with -gui (as opposed to using the backend interface directly) is to leave all the focus and gstate handing to NSView and NSWindow and draw from -drawRect:, so if it's at all possible, I strongly recommend doing that. If you need to trigger a redraw at some point, you just call -setNeedsDisplay:.
With other methods, you are (more or less) bypassing -gui's drawing infrastructure, and this is risky and prone to weird behavior. However, in practice, I've had few problems with something like:
(theView is a view that covers the area I want to draw. It probably helps if theView is opaque and has an empty -drawRect:.)
[theView lockFocus]; /* Draw here. */ [theView unlockFocus]; [[theView window] flushWindow];
Usually nothing shows in the window that I've created. Sometimes a rectangle appears as it should, but I can't figure out what triggers this or why, and it disappears on the next refresh.
Most likely, -gui is going through the normal redraw mechanism in response to something, and various -drawRect:s are drawing the window background on top of your view. They expect your view's -drawRect: to redraw your parts, so the fix is to make sure your -drawRect: does that.
(Using an opaque view should help a bit here since it tells -gui that it doesn't _have_ to clear the window behind your view. It doesn't fix the problem, though; -gui might clear the background anyway.)
- Alexander Malmberg
[Prev in Thread] | Current Thread | [Next in Thread] |