FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

WINDOWS

Change the background pattern of a window


Try the following demo. It switches the background pattern (via BACKPIXPAT), but the same techniques should apply to foreground patterns (PENPIXPAT) as well. The only problem I ran into was trying to restore the _original_ (white) background pattern (I was getting system errors), but I got around that by making a copy of the original pattern (COPYPIXPAT) and restoring to that copy. My first thought was that QuickDraw trashes the old pattern when you switch to the new (thus invalidating any handles to the old pattern that you may have had around), but it doesn't seem to do that when I toggle back & forth between ppat's.

The demo assumes you've got a resource file called "buncha ppat's", from which it gets ppat #131 and ppat #133. I just "borrowed" a couple of ppat's from the "Desktop Patterns" control panel (with ResEdit) and put them into "buncha ppat's".

Regarding disposal: DON'T dispose of a pixpat while the window is still using it. After you've closed the window, or switched the window to a different pattern, it should be safe to CALL DISPOSPIXPAT to dispose of the old pixpat (if you don't intend to use that pixpat again).

Rick

RESOURCES "buncha ppat's"
LOCAL FN TogglePatterns(p1&, p2&)
  done = _false
  DO
    CALL BACKPIXPAT(p1&)
    CLS
    timesUp& = FN TICKCOUNT + 60
    DO
      IF MOUSE(_down) THEN done = _zTrue
    UNTIL done OR FN TICKCOUNT >= timesUp&
    LONG IF NOT done
      CALL BACKPIXPAT(p2&)
      CLS
      timesUp& = FN TICKCOUNT + 60
      DO
        IF MOUSE(_down) THEN done = _zTrue
      UNTIL done OR FN TICKCOUNT >= timesUp&
    END IF
  UNTIL done
END FN
'========= main ==========
WINDOW 1
ppat1& = FN GETPIXPAT(131)
ppat2& = FN GETPIXPAT(133)
LONG IF ppat1& <> _nil AND ppat2& <> _nil
  wptr& = WINDOW(_wndPointer)
'Save original back pattern.
'For unknown reasons, it doesn't suffice to simply
'say "oldPattern& = wptr&.bkPixPat&". Instead, we
'have to make a new copy of the original pattern.
  oldPattern& = FN NEWPIXPAT
  CALL COPYPIXPAT(wptr&.bkPixPat&, oldPattern&)
  FN TogglePatterns(ppat1&, ppat2&)
'Restore original (white) pattern:
  CALL BACKPIXPAT(oldPattern&)
  CLS
XELSE
  BEEP
  CLS
  PRINT "Couldn't load ppat's!"
END IF
DO
  HANDLEEVENTS
UNTIL _false
'===================