Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!uunet!blkcat!f421.n109.z1.fidonet.org!Ken.Knight From: Ken.Knight@f421.n109.z1.fidonet.org (Ken Knight) Newsgroups: comp.sys.mac.programmer Subject: (R)Drawing to windows Message-ID: <3583.27C35477@blkcat.fidonet.org> Date: 20 Feb 91 22:04:20 GMT Sender: ufgate@blkcat.fidonet.org (newsout1.26) Organization: FidoNet node 1:109/421 - The Twilight Clone, Paul Heller Lines: 48 cabruen@athena.mit.edu (Charles Alan Bruen) writes [edited] >How should I store the information I want drawn in a window. (I know >how >to actually do it) IM suggests that you not draw to the screen directly >but save the information somehow (it fails to mention). > >Problem: In a window a have a plot of a function. I do all the >calculations as I draw the plot in the window. If I later get an update >event for that window, do I have to redo the calculations to redraw the >window. This seems like a big waste of effort. > >What are the ways in which this is solved in the real world? Could I >draw to an imaginary Picture and just put that in the window everytime >I >get an update? If re-plotting the function is fairly fast than tha is a perfectly reasonable way to go. However, for the fastest results you should use CopyBits(). The idea is to draw your plot in an offscreen bitmap and then draw that to the window whenever needed. For info on how to set up the bitmap check out the technotes on drawing to offscreen bitmaps. Also, most Mac programming books deal with it. It really isn't to tough. Apple has made many high-level routines that handle the drudgery of setting up an offscreen bitmap for you. Note, you can also simply create, though this isn't a perfect method a plain old grafport, draw into that, and then copybits() its bitmap to your window. Thus: setPort(&myNewPort); [ draw away ] on update events copyBits(&myNewPort->PortBits,&myWindow->PortBits,&someRect,&someRect, srcCopy, nil); That method should work as a starter. It has more overhead though. -- Ken Knight, Ken.Knight@f421.n109.z1.fidonet.org via The Black Cat's Shack's FidoNet<->Usenet Gateway blkcat.fidonet.org and Fidonet 1:109/401