[net.sources.mac] Macintosh programming. Help!

cutler@reed.UUCP (Steven J. Russell) (11/11/86)

I have a few questions pertaining to programming on the Macintosh in Pascal
(specifically LightSpeed Pascal).

          1. How do you get graphics to scroll smoothly?  I have a procedure
                  that draws graphics, and I want to get it to scroll.  I have
                  my scroll bars, and windows, etc.  Should I keep an offscreen
                  bitmap and scroll by CopyBits, or should I draw the image
                  each time.  Also, is there some formula that figures out what
                  a control's MaxValue should be when the image is bigger than
                  the window can show?  Source might be helpful.

          2. How do I update quickly?  This might be part of question 1.  Is
                  there any particular method that would update just the update
                  region instead of the whole image?  Source would be helpful.

          3. I seem to be having trouble with handling grows.  The trouble
                  seems to be with not erasing the scroll bars when enlarging
                  and not drawing them right when reducing by small amount.
                  How do you do this?

Thanks for any help (particularly source code) that you can lend me.  If you
have source, it would be most helpful in Pascal, but I will get by if it is in
C.  Even just the concepts behind scrolling, etc. would be of a great help.

One last question...

Has anyone written a Printer Driver in LightSpeed Pascal or LightSpeed C?  If
you have, I would be very interested in hearing about it, especially if it is
like the ImageWriter driver (dialog boxes, etc.).

Thanks for your help.

Steven J. Russell

DMB@PSUVMA.BITNET (11/12/86)

  About scrolling and updating fast:

     If you want to scroll in primarily fixed, rectangular reqions then
nothing beats ScrollRect for speed and ease of use. However for kind of
arbitrary scrolling, and the fact that you want to update quickly, the
the following scenario is probably better. Notice this illustration uses
fixed size windows, but it's possible with sizeable windows, but perhaps
a bit more sticky.

(* Set up an offscreen bitmap *)

Var offscreenbits:Bitmap;  (* the offscreen bitmap *)
    savebits:Bitmap;  (* a temporary bitmap for the windows portbits *)

(* initialize it to the size of the window: *)
  offscreenbits.rowbytes := thewindow@.portbits.rowbytes;
  (* @ is really up arrow I can't seem to type it here *)
  offscreenbits.bounds := thewindow@.portbits.bounds;
  bitsize := (thewindow@.portrect.bottom-thewindow@.portrect.top) *
             tempbits.rowbytes * 8;
  offscreenbits.baseaddr := Newptr(sizeof(bitsize);

  (* Save the window's portbits in a temporary bitmap and set the windows
     portbits to our offscreen bitmap *)

  savebits := thewindow@.portbits;
  setportbits(offscreenbitmap); (* sets the frontwindows bitmap notice *)
  eraserect(thewindow@.portrect); (* clear out the offscreen bitmap *)

(* Whenever you draw you can just draw into the window like normal as in *)
invertrect(thewindow@.portrect);
invertrect(thewindow@.portrect);
(* etc.... *)
(* When ever you draw now, it won't appear on the screen *)
(* when you want to put up on the screen what you've drawn call a procedure
   to update the screen, Let's call it updatescreen *)

Procedure updateScreen;
begin
   SetPortBits(tempbits);
   CopyBits(offscreenbits,thewindow@.portbits,offscreenbits.bounds,
            thewindow@.portrect,mode,maskrgn);
   (* note: mode is the overlay transfer mode, you probably want SrcCopy *)
   (*       maskrgn is the rgn you want to copy, if nil the whole rect
            is copied *)
   SetPortBits(offscreenbitmap);
end;

(* As for quick updates, this procedure makes life simple, The mac keeps a rgn
   which is the rgn that has to be redrawn, when a window deactivates in front
   of it, or you move the window off screen or what ever. Therefore to update
   do the following *)

   case
   .......
     updateevt:begin
                  BeginUpdate(theupdatewindow);
                     UpdateScreen;
                  EndUpdate(theupdatewindow);
               end;
    .......
    (* notice theupdatewindow is the window returned by findwindow *)


   That should do it, notice again this assumes fixed size windows, if you
   allow variable sized windows you'll probably have to smudge this alittle
   for when you change the size of the window, but anyway....
   Hopefully i haven't made any silly mistakes, but then again i guess i hear
   about it if i did, there's nothing worse then getting misinfo.
   **** Good Luck ****

                                  dave brosius
                                  PSUVMA.bitnet
Insert comment here: