Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!apple!well!smoke From: smoke@well.sf.ca.us (Nicholas Jackiw) Newsgroups: comp.sys.mac.programmer Subject: Re: Tracking the mouse. Keywords: source code Message-ID: <21469@well.sf.ca.us> Date: 2 Nov 90 19:45:46 GMT References: <1990Oct31.100603.1989@agate.berkeley.edu> <21455@well.sf.ca.us> <21464@well.sf.ca.us> Organization: Whole Earth 'Lectronic Link, Sausalito, CA Lines: 81 In article <21464@well.sf.ca.us> oster@well.sf.ca.us (David Phillip Oster) writes: [blah blah blah] >(To get flicker free, stamp your >offscreen bitmap with the image of the cursor.) >-- David Phillip Oster - Note new signature. Old one has gone Bye Bye. What an excellent and obvious idea! Makes me feel like a dolt, the amount of satisfaction I get out of my offscreen routines despite the fact that the cursor's quivering like a biker mad on booze and speed. Here's some cheap code to accomplish it. THINK Pascal 3.0. Note that you'll not want to call it for the final frame of an animation, or else the stamped cursor will linger permanently in that frame. procedure StampCursor; {By Nick Jackiw 11/2/90 - idea from David Phillip Oster.} {Use wantonly and rewrite as necessary. Color cursor} {support should be a trivial addition.} {StampCursor, assuming that thePort is currently set to an} {offscreen bitmap which is going to be copied to the screen,} {draws the current cursor at the current mouse location in that port.} {This helps minimize the flicker that occurs when a cursorless} {offscreen image is copied over the current screen cursor.} {This implementation assumes the presence of a few global variables:} { - GlobalCurs is the cursor most recently set with SetCursor.} { - OffWorld and OnWorld are two bitmaps describing the offscreen} { and onscreen drawing environments.} { - OffCWorld and OnCWorld are similar, but are pixmaps} { - hasCQD indicates whether to use pixmaps or bitmaps} var cursBits, maskBits: BitMap; aPt: point; begin GetMouse(aPt);{Let Quickdraw localize the mouseLoc to our offscreen port} with aPt do {then adjust it by the difference between offscreen and onscreen} if hasCQD then with OffCWorld^^.bounds do begin h := h + OnCWorld^^.bounds.left - left; v := v + OnCWorld^^.bounds.top - top end else with OffWorld.bounds do begin h := h + OnWorld.bounds.left - left; v := v + OnWorld.bounds.top - top end; with cursBits do {Generate bitmaps describing the cursor and its mask} begin {in positions relative to the localized mouse point} with bounds do with GlobalCurs.HotSpot do with thePort^ do begin top := aPt.v - (v); left := aPt.h - (h); right := left + 16; bottom := top + 16 end; rowBytes := 2; baseAddr := @GlobalCurs.data end; maskBits := cursBits; maskBits.baseAddr := @GlobalCurs.mask; with cursBits do {image and clip it appropriately to the present port} CopyMask(cursBits, maskBits, thePort^.portBits, bounds, bounds, bounds) end; -- --- * --- Nicholas Jackiw Smoke@well.sf.ca.us | Jackiw@cs.swarthmore.edu Key Curriculum Press, Inc. Applelink: D3970 | (415) 548-2304 --- * ---