[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Drawing to screen - nothing appears?
From: |
Steven |
Subject: |
Re: Drawing to screen - nothing appears? |
Date: |
Sat, 20 Nov 2004 10:50:16 -0800 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
[I just realized that I replied directly instead of the list - sorry]
I meant as in an instance of the class - but for some odd reason
neither the OS X nor the Linux gcc gave me even a warning about the
fact that there appears to be no -lockFocus for NSWindow! I changed
the application to use drawRect, and all seems well for now. I'm using
- - -display instead of -setNeedsDisplay: because I'm running this in a
tight loop and it needs to be updated inside of it. Apparently Cocoa
is a bit more lenient towards sloppy code ;)
Thanks a bunch!
On Nov 20, 2004, at 4:46 AM, Alexander Malmberg wrote:
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_pre20041116
I'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
_______________________________________________
Gnustep-dev mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/gnustep-dev
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)
iD8DBQFBn5HpjRUeSe4yhVoRAp4AAJ0ceJ9c9RRHaOH2hxrzNTe09pQHSgCeNz+8
q0LaAD/CrERVDxzdBwls3DI=
=rbt7
-----END PGP SIGNATURE-----