[comp.sys.mac.programmer] Basic Programming Question ?

tim@hoptoad.uucp (Tim Maroney) (02/01/90)

In article <1059ghassemi@yvax.byu.edu> ghassemi@yvax.byu.edu writes:
>I am a beginner in Mac programming (and with limited experience in programming
>in general).  I have been trying to learn to program the mac interface by
>extending a sample paint program that came with my Lightspeed (Think) Pascal
>(v.1.11).  One of the features I would like to add is movable windows.  If the
>window is dragged so that it is only partially on the screen, the contents of
>the part off screen is lost.  My problem is updating the window when it has
>been draged back on screen.
>I can partially solve the problem with keeping an extra copy of the window's
>contents in a separate grafport off screen.  The difficulty with this is that
>if my widow gets larger than a certain size then the program crashes with
>"Application zone damaged" and "out of memory" messages. (I have a Mac SE with
>1 meg memory, no multifinder.)

That's strange.  Are the window contents a bitmap or a picture?  The
maximum size bitmap displayable on an SE screen should be about 20K;
the memory for a whole MacPaint page is about 50K.  This should not be
a memory problem with a full megabyte application partition (to say the
least).  It must be a bug in your code.  I'm not clear on what you mean
by an offscreen grafport; grafports don't save their contents (except
during an OpenPicture/ClosePicture).  If you're expecting it to save
what you draw into it, you're out of luck.  If you mean an offscreen
bitmap, then this is indeed the way to solve the problem.  You should
keep some sort of document-specific information in the refCon of the
window, or in a global if you only have one window, and use CopyBits to
update from your stored bitmap onto the screen in response to an update
event.  Offscreen bitmaps can be a little hairy for beginners, so make
sure you keep your code as simple as possible and scrutinize every
statement carefully for possibly unfounded assumptions about the
behavior of bitmaps.

>Another solution has been to make a copy (with Blockmove rou it requires very
>careful
>computation of the number and positions of the relevant bytes (and bits).  Not
>a very elegant solution!

Also illegal; you will crash on color systems.  Don't ever copy bitmaps
out of the main screen bitmap.

>It seems that for text editing, TextEdit routines of the toolbox provide a nice
>solution for such problems.  What about paint programs?

Keep an external bitmap or picture, and draw into those when the user
makes changes (as well as onto the screen).  Don't copy the bitmap out
of the screen itself.  Use CopyBits or DrawPicture when you get an
update event.  And write if you have problems.
-- 
Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com

FROM THE FOOL FILE:
"The men promise to provide unconditionally for their wives.  The women in turn
 serve unconditionally to provide the other household services necessary for the
 men to fulfill their obligations to the women.  The women are satisfied because
 they have the men working for THEM." -- Colin Jenkins, soc.women