[comp.sys.mac.programmer] portBits update in the current GrafPort

borcelf@jacobs.cs.orst.edu (Fernando Borcel) (01/11/89)

Ok.  Here's my problem.  I'm drawing simple stuff on my window, which I 
pressume is saved in theport^.portbits and mywindow^.portbits.  Now, when I
update mywindow, I'm not getting what I drew back at all.  Somebody wanna
give me a hand???

{This is what my update code looks like.  }

updateEvt : 
  begin
   tempwindow := windowptr(myevent.message);
   BeginUpdate(tempwindow);
   EraseRect(theport^.portrect);
   visrect := tempwindow^.portrect;
   copybits(tempwindow^.portbits, theport^.portbits, visrect, visrect, srccopy,
      theport^.visrgn);
   EndUpdate(tempwindow);
  end;

{-------}

Thanks!!!

	-Fernando

		
    ___                       __                |{tektronix,hp-pcd}!orstcs!
   /   _  _  _  _  _  _/ _   /_/  _  _  _  _ /  |  jacobs.cs.orst.edu!borcelf
  /- /_// // / _// // // /  /  )/ // //  /_//   | 
_/  /_ /  / //_// //_//_/  /__//_//  /_ /_ /_   |borcelf@jacobs.cs.orst.edu 

oster@dewey.soe.berkeley.edu (David Phillip Oster) (01/12/89)

In article <8186@orstcs.CS.ORST.EDU> borcelf@jacobs.cs.orst.edu (Fernando Borcel) writes:
...
>   BeginUpdate(tempwindow);
	SetPort(tempwindow);
>   EraseRect(theport^.portrect);
...

Well, one error is that BeginUpdate modifies the visRgn of its argument
temporarily (EndUpdate puts it back.), but it doesn't make it the current
port.  You must do that explicitly.  It is wise to save the old port so
you can restore it.

--- David Phillip Oster            --"When we replace the mouse with a pen,
Arpa: oster@dewey.soe.berkeley.edu --3 button mouse fans will need saxophone
Uucp: {uwvax,decvax}!ucbvax!oster%dewey.soe.berkeley.edu --lessons." - Gasee

vincent@ditsyda.oz (David A. Vincent) (01/14/89)

in article <8186@orstcs.CS.ORST.EDU>, borcelf@jacobs.cs.orst.edu (Fernando Borcel) says:
> 
> Ok.  Here's my problem.  I'm drawing simple stuff on my window, which I 
> pressume is saved in theport^.portbits and mywindow^.portbits.  Now, when I
> update mywindow, I'm not getting what I drew back at all.  Somebody wanna
> give me a hand???
> 
> {This is what my update code looks like.  }
[...]
>    tempwindow := windowptr(myevent.message);
>    BeginUpdate(tempwindow);
>    EraseRect(theport^.portrect);
>    visrect := tempwindow^.portrect;
>    copybits(tempwindow^.portbits, theport^.portbits, visrect, visrect, 
[...]

The effect of the copybits() call at that point will probably be
to copy the portBits of tempwindow (which you're updating) to
thePort (the current port, which will have been set to tempwindow by
the BeginUpdate() call).  That is, you're copying something onto itself.

Even though that copybits call might appear to be referring to two
distinct bitmaps, they will usually be the same bitmap (the screen's bitmap).

It looks as if you are unclear about the distinction between
grafPorts and BitMaps.  I will try to give a brief explanation, but
all this information is in IM v1.  When you create a window using
NewWindow() or GetNewWindow() the Window Manager calls openPort() to
create a new grafPort for the window.  Normally a call to openPort() 
creates a new grafPort whose portBits is screenBits, the screen's 
BitMap.  Most windows have screenBits as their grafPort's BitMap, 
but they all 'see' it differently 'through' their own grafPort.  (On a
multi-monitor setup this gets more complicated!  I guess there's one
BitMap for each monitor.)  

It looks as if you want a separate BitMap independent of the
screen so that you can draw your window's contents into it only when
the contents change, then copy that image onto the screen whenever
the screen image needs updating.  To do this you need to allocate your 
own BitMap (distinct from screenBits) before you draw the window contents.  
Every time the contents change you draw the new image into this BitMap; in
response to an update event you copy this BitMap onto the window's
(i.e. the screen's) portBits BitMap.  

I hope this helps.  Let me know if you need an example or more
explanation (or perhaps another reader has an example handy?)  

> 
> Thanks!!!
You're Welcome!!!
> 
> 	-Fernando
> 
...D.A.V.
D