home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / apps.to.go / DTS.Lib / DTS.Lib.headers / GWLayers.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-08  |  28.1 KB  |  608 lines  |  [TEXT/MPS ]

  1. #ifndef __GWLAYERS__
  2. #define __GWLAYERS__
  3.  
  4. #ifndef __TYPES__
  5. #include "Types.h"
  6. #endif
  7.  
  8. #ifndef __MEMORY__
  9. #include <Memory.h>
  10. #endif
  11.  
  12. #ifndef __QDOFFSCREEN__
  13. #include <QDOffscreen.h>
  14. #endif
  15.  
  16. #ifndef __QUICKDRAW__
  17. #include <Quickdraw.h>
  18. #endif
  19.  
  20. struct LayerRec;
  21. typedef struct LayerRec *LayerRecPtr, **LayerObj;
  22.  
  23. typedef OSErr (*LayerProc)(LayerObj theLayer, short message);
  24.  
  25. typedef struct LayerRec {
  26.     LayerObj        aboveLayer;
  27.     LayerObj        belowLayer;
  28.     Boolean         layerOwnsPort;
  29.     GrafPtr            layerPort;
  30.     GDHandle        layerGDevice;
  31.     Handle            layerBitmap;
  32.     short            layerDepth;
  33.     LayerProc        layerProc;
  34.     unsigned long    layerData;
  35.     short            xferMode;
  36.     Rect            srcRect;
  37.     Rect            dstRect;
  38.     Rect            thisUpdate;
  39.     Rect            lastUpdate;
  40.     Boolean            includeLastUpdate;
  41.     Boolean            lockedCount;
  42.     Boolean            cachedCount;
  43.     CGrafPtr        cachedPort;
  44.     GDHandle        cachedGDevice;
  45. } LayerRec;
  46.  
  47. #define kLayerInit    0
  48. #define kLayerDispose 1
  49. #define kLayerUpdate  2
  50.  
  51. OSErr    NewLayer(LayerObj *newLayer, LayerObj aboveLayer, LayerProc theProc,
  52.                  GrafPtr basePort, short depth, unsigned long theData);
  53.     /*
  54.     **    ¶ Create a layer object for offscreen drawing.
  55.     **
  56.     **    INPUT:    aboveLayer        This is the layer above the layer to create.
  57.     **                            If the layer is to be the top layer, then pass nil here.
  58.     **            theProc            The procedure pointer for the layer object.  If the default
  59.     **                            actions are all okay, then pass in nil here.
  60.     **            basePort        If you pass in a port here, then NewLayer won’t create one
  61.     **                            for you.  If no port is passed in, then it will create an
  62.     **                            offscreen GWorld (or port for system 6), based on the size/depth
  63.     **                            of the layer above (and some other factors).
  64.     **            depth            The depth to create the offscreen.  If 0 is passed in, then
  65.     **                            the depth is based on the above port.
  66.     **            theData            Application reference field.  Store whatever you want here.
  67.     **    OUTPUT:    newLayer        If successful, a LayerObj handle will be returned here.
  68.     **                            If unsuccessful, a nil will be returned here.
  69.     **    RESULT:    OSErr            The most likely error is memFullErr.
  70.     **
  71.     **    GWLayers is meant to simplify and standardize offscreen drawing in a flexible way.
  72.     **
  73.     **    NOTE:    This package was originally written for use with GWorlds, but system 6
  74.     **            support has been added.  You no longer need system 7 or color quickdraw
  75.     **            to use this package.
  76.     **
  77.     **    Using offscreen GWorlds allows applications to achieve very clean graphics
  78.     **    effects that are not possible if drawing directly to a window (or grafPort).
  79.     **    In most cases, when an image is generated in an offscreen GWorld, that image
  80.     **    will end up being displayed in a window.
  81.     **
  82.     **    This relationship between offscreen GWorlds and windows needs to be managed.
  83.     **    In addition to one GWorld relating to a window, you may actually need multiple
  84.     **    GWorlds to relate to a window.  Many effects demand more than one offscreen
  85.     **    GWorld.  Smoothly dragging an image over a background is one such effect.
  86.     **
  87.     **    GWLayers.c is a block of code that manages the more mundane aspects of handling one
  88.     **    or more GWorlds.  GWLayers.c gives you a consistent way of relating GWorlds/windows
  89.     **    together.
  90.     **
  91.     **    A common use for offscreen GWorlds is to move an object around in a window smoothly
  92.     **    over a background.  To accomplish this, we need 3 layers.
  93.     **    These are:
  94.     **
  95.     **    1)    The window layer.  This is the top-most layer in the layer hierarchy.  The
  96.     **        top-most layer is typically what the user will see, and therefore commonly
  97.     **        is a window layer.  Layers below the top-most are typically offscreen
  98.     **        GWorlds.
  99.     **    2)    A middle layer that is used to apply the object being moved to the
  100.     **        background plus removing the object from the old location.  Once these
  101.     **        two tasks are done, the offscreen work area is ready to be transferred
  102.     **        to the window layer.
  103.     **    3)    A background image against which the object moves.  This is used to
  104.     **        restore the middle layer at the location where the object being moved
  105.     **        was last at.
  106.     **
  107.     **    The background layer is generated only once.  The relevant (changing) portions of
  108.     **    the background image are copied into the middle layer.  Once the background portion
  109.     **    is copied into the middle layer, the object that is moving across the background is
  110.     **    drawn into the middle layer on top of the background portion.
  111.     **
  112.     **    Once the middle layer has the background portion with the moving object drawn onto it,
  113.     **    the portion is transferred to the top-most layer, which is the window layer.  The user
  114.     **    sees only this final transfer, so the intermediate steps are completely hidden.  The
  115.     **    user just sees the object being dragged drawn into its new location.
  116.     **
  117.     **    To make the dragged object seem to move, it is also important to erase it from its
  118.     **    old location.  If this were done in two steps (restore old location, draw in new location),
  119.     **    the movement would flicker.  The user would be able to perceive (very easily) that
  120.     **    the object is first removed from the old location and the redrawn in the new location.
  121.     **    To prevent this flickering, the old location and the new location have to be updated
  122.     **    in a single step.  Working offscreen allows this.  The middle layer is first updated so
  123.     **    that the old location of the object is restored to background.  The middle layer then has
  124.     **    the object drawn into the new location.  And then when the transfer finally occurs into
  125.     **    the window layer, an area large enough to cover both the old location and the new location
  126.     **    are transferred at once with a single CopyBits.
  127.     **
  128.     **
  129.     **    GWLayers.c conventions:
  130.     **
  131.     **    Updating of each layer is handled by the layer itself.  A particular layer checks to
  132.     **    see if there is a layer below, and if there is, does a CopyBits of the relevant area
  133.     **    from the below layer into itself.  If after the CopyBits there is any additional
  134.     **    drawing needed (such as the middle layer in the above example), then it is typically
  135.     **    done after the CopyBits.
  136.     **
  137.     **    Since the layers actually need to update from the bottom-most layer to the top-most
  138.     **    layer (top-most being the window, showing the final result), the layer updating code
  139.     **    checks to see if there is a layer below.  If there is, then the update procedure is
  140.     **    called for the layer below.  This recursion continues until the bottom-most layer is
  141.     **    reached.  The bottom-most layer then does its thing.  (For the case where the bottom-most
  142.     **    layer is background this "thing" will be to do nothing.)  Once the update for the layer
  143.     **    is completed, the update procedure simply returns.  It will return to the caller, which
  144.     **    is the layer above it (if any).  The next layer up does its thing, and then returns, and
  145.     **    so on.  This recursive chain of layers allows the updating to happen automatically in
  146.     **    the order designated by the layer hierarchy.
  147.     **
  148.     **    Since window records and GWorld records don't have any fields for all of the stuff we
  149.     **    need to keep (such as above-layer, below-layer, update procedures, etc.), this
  150.     **    implementation uses a handle to hold the layer record.  Each layer record has a reference
  151.     **    to the window or GWorld is is to draw into, plus a reference to what layers records
  152.     **    are above and below, if any.  The structure for a layer record is as follows:
  153.     **
  154.     **    typedef struct LayerRec {
  155.     **        LayerObj        aboveLayer;            Nil if no above layer.
  156.     **        LayerObj        belowLayer;            Nil if no below layer.
  157.     **        Boolean         layerOwnsPort;        True if layer created the GWorld.
  158.     **        GrafPtr            layerPort;            Window or GWorld this layer draws into.
  159.     **        GDHandle        layerGDevice;        The GDevice for this layer.
  160.     **        Handle            layerBitmap;        If GWorlds aren't available, this holds the bitmap.
  161.     **        short            layerDepth;            Requested NewLayer depth of pixmap.
  162.     **        LayerProc        layerProc;            Layer procedure.  If nil, then default behaviors used.
  163.     **        unsigned long    layerData;            Application refCon-type field.
  164.     **        short            xferMode;            Transfer mode for CopyBits.
  165.     **        Rect            srcRect;            Initially nil, which makes entire GWorld source.
  166.     **        Rect            dstRect;            Initially nil, which makes entire window/GWorld dest.
  167.     **        Rect            thisUpdate;            Area to be updated for this update.
  168.     **        Rect            lastUpdate;            Area updated last time UpdateLayer was called.
  169.     **        Boolean            includeLastUpdate;    True is last updated area is o updated as well.
  170.     **        Boolean            lockedCount;        Used internally by GWorld locking/unlocking calls.
  171.     **        Boolean            cachedCount;        Used internally by GWorld locking/unlocking calls.
  172.     **        CGrafPtr        cachedPort;            Used internally by GWorld usage calls.
  173.     **        GDHandle        cachedGDevice;        Used internally by GWorld usage calls.
  174.     **    } LayerRec;
  175.     **
  176.     **    layerOwnsPort:
  177.     **        If the layer created the GWorld, then it is the layer's responsibility to get rid
  178.     **        of its GWorld when the layer is disposed of.  If this flag is true, the GWorld
  179.     **        will be disposed of when the layer is disposed of.
  180.     **
  181.     **    layerProc:
  182.     **        This is nil if the default behaviors are acceptable for a particular layer.
  183.     **        If this is non-nil, then you are responsible for implementing each layer
  184.     **        message behavior.  (More on this later.)
  185.     **
  186.     **    xferMode:
  187.     **        This is the transfer mode for CopyBits.  The default behavior for updating simply
  188.     **        transfers some or all of the below layer (if there is one) into the current layer.
  189.     **        It does this with CopyBits, using the designated transfer mode.
  190.     **
  191.     **    srcRect:
  192.     **        This is initially an empty rect.  If this srcRect is empty, then the portRect of the
  193.     **        GWorld is used as the srcRect.  This means the default srcRect is the entire GWorld.
  194.     **        If this field is set to a non-empty rect, the default update behavior is to do a CopyBits
  195.     **        of just the srcRect area, and not the entire GWorld.  (Remember, the CopyBits is done by
  196.     **        the above layer, so only if the above layer uses the default update behavior does this
  197.     **        occur automatically.)
  198.     **        Having a srcRect smaller than the entire GWorld allows for additional effects, such as
  199.     **        fat-bits.  If the srcRect for this layer is smaller than the dstRect of the above layer,
  200.     **        CopyBits will transfer a small rect into a big rect.  The image will be scaled to
  201.     **        accommodate the larger destination rect, and presto -- fat-bits!!
  202.     **
  203.     **    dstRect:
  204.     **        This field is initially an empty rect, just like srcRect.  If dstRect is set to a
  205.     **        non-empty rect, then the default update behavior will CopyBits only into this area.
  206.     **        This allows targeting of a specific portion of a window for offscreen updating, while
  207.     **        the rest of the window can be used from scrollbars, or some such other thing.
  208.     **
  209.     **    thisRect:
  210.     **        This field is also initially an empty rect.  This field becomes non-empty by
  211.     **        calling InvalLayer.  InvalLayer unions the rect passed to it into thisRect and
  212.     **        stores the result in thisRect.  It then calls itself if there is a below layer, thus
  213.     **        recursively changing thisRect for all layers below it in the layer hierarchy.
  214.     **
  215.     **    lastRect:
  216.     **        This field is also initially an empty rect.  This field becomes non-empty after
  217.     **        thisRect is non-empty and then UpdateLayer is called.  Once the update is done,
  218.     **        thisRect is copied into lastRect, and then thisRect is set empty once again.
  219.     **        The lastRect field is use to optionally combine updating the last update with the
  220.     **        current update.  This is particularly useful for dragging objects, as described above.
  221.     **        In a single CopyBits, the old location and the new location need to be drawn in the
  222.     **        window.  By setting includeLastUpdate true, this is done automatically by the default
  223.     **        update behavior.
  224.     **
  225.     **    includeLastUpdate:
  226.     **        As just described for the lastRect field, if this field is true, then the default
  227.     **        update behavior CopyBits includes both the last update and this update, thus generating
  228.     **        smooth animation effects.
  229.     **
  230.     **
  231.     **    A call to create a layer for a window (the top-most layer, most likely) might look like this:
  232.     **
  233.     **        NewLayer(&windowLayer,    Layer object handle is returned here.
  234.     **                  nil,            Top layer, so there is no above layer.
  235.     **                  nil,            Uses default layer procedure.
  236.     **                  window,         Window used by the layer object.
  237.     **                  0,              Depth for offscreen 0 for screen depth).
  238.     **                  0);             Custom layer init data, if any.
  239.     **
  240.     **    If NewLayer succeeds, the layer object handle is returned in windowLayer.  If it fails,
  241.     **    nil is returned in windowLayer, plus an error is returned.  This call can hardly fail, as
  242.     **    there is no offscreen GWorld created.  If only a minimally-sized handle can be created, it
  243.     **    will succeed.
  244.     **
  245.     **    To create a work layer below this window layer, we might make a call such as:
  246.     **
  247.     **        err = NewLayer(&workLayer, windowLayer, WorkLayerProc, nil, 0, (long)&myInfo);
  248.     **                myInfo is a struct that holds information that WorkLayerProc
  249.     **                needs to reference for drawing the object in the new location.
  250.     **
  251.     **    This call has a greater chance of failure, as an offscreen GWorld was created for it.
  252.     **    We passed it a nil grafPort, so the default initialization behavior knows that it will
  253.     **    have to create a GWorld.  The default initialization behavior uses dstRect of the above
  254.     **    layer as the size of the offscreen GWorld it is to create.  If dstRect is an empty rect,
  255.     **    then it uses the portRect of the above layer instead.  So if you wanted to map the offscreen
  256.     **    layer to just a portion of the window, you would set the dstRect for the top-most layer
  257.     **    prior to creating the middle layer.
  258.     **
  259.     **    IMPORTANT:  The default behavior automatically creates the offscreen GWorld to the described
  260.     **                size.  We have passed NewLayer a layer procedure, so we don't automatically get
  261.     **                the default behaviors for the middle layer.  This must be kept in mind when
  262.     **                writing the layer procedure for the middle layer.  To get the default behavior,
  263.     **                we simply call DefaultLayerInit when the layer procedure gets an initialization
  264.     **                message.  Since the default initialization behavior is exactly what we want, we
  265.     **                just call it directly.
  266.     **
  267.     **    The reason that we have a layer procedure for this layer is that we want to do something
  268.     **    different when we receive an update message.  For the update message we want to first
  269.     **    transfer the portion of background into the middle layer, and then we want to draw the object
  270.     **    we are dragging into the middle layer.  For the update message, we can first call
  271.     **    DefaultLayerUpdate to do the CopyBits from the below layer into the middle layer, and then
  272.     **    right after that we can draw the object being dragged into its new location.  The neat thing
  273.     **    about this is that the default behavior can still commonly be used, even if there is extra
  274.     **    stuff that we need to do.
  275.     **
  276.     **    Assuming no errors, we now have a top-most layer relating to the target window, plus a middle
  277.     **    layer for doing the offscreen drawing of the object being dragged.  We now need a background
  278.     **    layer that has an image of the background drawn into it.  This code might look like:
  279.     **
  280.     **        if (!err) err = NewLayer(&backLayer, workLayer, BackLayerProc, nil, 0, (long)&myInfo);
  281.     **
  282.     **    This layer also has its own layer procedure.  The reasoning behind this is that the
  283.     **    initialization would do the drawing into the background.  Once the layers are all set up,
  284.     **    we want the background layer to be fully imaged.  This way there is no time spent for the
  285.     **    background layer, which is the way a background should be.
  286.     **
  287.     **    To recap, the code to create the 3 layers is as follows:
  288.     **
  289.     **                        NewLayer(&windowLayer, nil, nil, window, 0, 0);
  290.     **                  err = NewLayer(&workLayer, windowLayer, WorkLayerProc, nil, 0, (long)&myInfo);
  291.     **        if (!err) err = NewLayer(&backLayer, workLayer, BackLayerProc, nil, 0, (long)&myInfo);
  292.     **
  293.     **    For dragging, we would then have some sort of loop, such as:
  294.     **
  295.     **        Assume the location where the user clicked is already in mouseLoc, local coordinates.
  296.     **
  297.     **        if (err) return;        No ram for the offscreen stuff.
  298.     **
  299.     **        lastLoc.h = lastLoc.v = -32767;        Unclickable initial point.
  300.     **        while (StillDown()) {
  301.     **            if ((lastLoc.h != mouseLoc.h) || (lastLoc.v != mouseLoc.v)) {  Always true first time.
  302.     **                rct.top  = rct.bottom = mouseLoc.v;
  303.     **                rct.left = rct.right  = mouseLoc.h;
  304.     **                rct.bottom += myInfo.objectHeight;
  305.     **                rct.right  += myInfo.objectWidth;
  306.     **                InvalLayer(windowLayer, rct, true);        Update last location, as well as this one.
  307.     **                UpdateLayer(windowLayer);
  308.     **                lastLoc = mouseLoc;
  309.     **            }
  310.     **        }
  311.     **
  312.     **        DisposeThisAndBelowLayers(windowLayer);
  313.     **
  314.     **    As can be seen above, smoothly dragging an object can be very little code.  There are a few
  315.     **    things not handled by the above code, such as if there isn't enough memory for the offscreen
  316.     **    GWorlds.  It isn't really polite to do nothing, as the above code does.  For exception
  317.     **    handling, please see the actual sample code that uses the GWLayers.c package. */
  318.  
  319. void    DetachLayer(LayerObj theLayer);
  320.     /*
  321.     **    ¶ Detach the layer from the layer chain.
  322.     **
  323.     **    INPUT:    theLayer        This is the layer to detach.  If nil is passed in, then
  324.     **                            no action is taken.
  325.     **
  326.     **    Use this call to remove a layer from a layer hierarchy.  This call does
  327.     **    not dispose of the layer. */
  328.  
  329. OSErr    DisposeLayer(LayerObj theLayer);
  330.     /*
  331.     **    ¶ Detach the layer from the layer chain, and then dispose it.
  332.     **
  333.     **    INPUT:    theLayer        This is the layer to detach/dispose.  If nil is passed in,
  334.     **                            then no action is taken.
  335.     **
  336.     **    Dispose of the layer.  If the layer belongs to a hierarchy, it is first
  337.     **    removed from that hierarchy. */
  338.  
  339. OSErr    DisposeThisAndBelowLayers(LayerObj theLayer);
  340.     /*
  341.     **    ¶ Dispose the layer and all layers below it from the layer chain.
  342.     **
  343.     **    INPUT:    theLayer        This is the top layer to detach/dispose.  If nil is passed in,
  344.     **                            then no action is taken.
  345.     **
  346.     **    Dispose of the layer and all layers below it in the hierarchy. */
  347.  
  348. short    GetLayerPosition(LayerObj theLayer);
  349.     /*
  350.     **    ¶ Return the layer position in the hierarchy.
  351.     **
  352.     **    INPUT:    theLayer    This is the layer to determine position for.  If nil is passed in,
  353.     **                        then no action is taken.
  354.     **
  355.     **    Return the layer position in the hierarchy.  0 is the top layer. */
  356.  
  357. LayerObj    GetTopLayer(LayerObj theLayer);
  358.     /*
  359.     **    ¶ Return the top layer in the hierarchy.
  360.     **
  361.     **    INPUT:    theLayer    This is the layer somewhere in the chain.  If nil is passed in,
  362.     **                        then no action is taken.
  363.     **
  364.     **    Return the top layer in the hierarchy. */
  365.  
  366. LayerObj    GetBottomLayer(LayerObj theLayer);
  367.     /*
  368.     **    ¶ Return the bottom layer in the hierarchy.
  369.     **
  370.     **    INPUT:    theLayer    This is the layer somewhere in the chain.  If nil is passed in,
  371.     **                        then no action is taken.
  372.     **
  373.     **    Return the bottom layer in the hierarchy. */
  374.  
  375. void    InsertLayer(LayerObj theLayer, LayerObj referenceLayer, short pos);
  376.     /*
  377.     **    ¶ Insert a layer into a hierarchy.
  378.     **
  379.     **    INPUT:    theLayer        This is the layer to add to the chain.
  380.     **            referenceLayer    This is any layer in the hierarchy theLayer is being added to.
  381.     **            pos                This is the position in the hierarchy that theLayer is being
  382.     **                            added as.
  383.     **
  384.     **    Insert a layer into a hierarchy.  Passing a 0 for position makes the layer the top layer. */
  385.  
  386. OSErr    UpdateLayer(LayerObj theLayer);
  387.     /*
  388.     **    ¶ Return the bottom layer in the hierarchy.
  389.     **
  390.     **    INPUT:    theLayer    This is the layer to update.  If nil is passed in,
  391.     **                        then no action is taken.
  392.     **
  393.     **    Given that a layer update has been posted, do the update.  LayerUpdate does
  394.     **    a recursive update from theLayer down.  If there is a layer below, it calls
  395.     **    LayerUpdate for that layer.  Once the bottom of the hierarchy is reached,
  396.     **    the layerProc is called to do the update.  This causes the layer updates to
  397.     **    occur from bottom up. */
  398.  
  399. Rect    GetEffectiveSrcRect(LayerObj theLayer);
  400.     /*
  401.     **    ¶ Get the effective (logical) source rect for the layer.
  402.     **
  403.     **    INPUT:    theLayer    This is the layer to get the source rect for.  If nil is passed in,
  404.     **                        then no action is taken.
  405.     **
  406.     **    The effectiveSrcRect is srcRect or portRect of the layer.  If there is no srcRect,
  407.     **    (srcRect is empty), then effectiveSrcRect is the layer's portRect. */
  408.  
  409. Rect    GetEffectiveDstRect(LayerObj theLayer);
  410.     /*
  411.     **    ¶ Get the effective (logical) destination rect for the layer.
  412.     **
  413.     **    INPUT:    theLayer    This is the layer to get the destination rect for.  If nil is passed in,
  414.     **                        then no action is taken.
  415.     **
  416.     **    The effectiveDstRect is dstRect or portRect of the layer.  If there is no dstRect,
  417.     **    (dstRect is empty), then effectiveDstRect is the layer's portRect. */
  418.  
  419. OSErr    DefaultLayerProc(LayerObj theLayer, short message);
  420.     /*
  421.     **    ¶ Get the effective (logical) destination rect for the layer.
  422.     **
  423.     **    INPUT:    theLayer    This is the layer to take action on.  If nil is passed in,
  424.     **                        then no action is taken.
  425.     **
  426.     **    The three currently defined message definitions are:
  427.     **
  428.     **    kLayerInit:        Called by NewLayer.  If layerPort is nil (which was
  429.     **                    initialized by NewLayer), then the size/depth of the GWorld
  430.     **                    that is created is dependent on aboveLayer.  If there is no
  431.     **                    aboveLayer, this is an error, and paramErr is returned.
  432.     **                    If the GWorld is successfully created, then layerOwnsPort is
  433.     **                    set true.
  434.     **    kLayerDispose:    Called when a layer is disposed of by either DisposeLayer or
  435.     **                    DisposeThisAndBelowLayers.  It disposes of the GWorld if the
  436.     **                    GWorld is owned by the layer.
  437.     **    kLayerUpdate:   If there is a below layer, kLayerUpdate does a CopyBits from the
  438.     **                    below layer into the current layer.  The copy is done from the
  439.     **                    below layer's effectiveSrcRect into the current layer's
  440.     **                    effectiveDstRect.  The transfer mode used is in xferMode, which
  441.     **                    by default is srcCopy. */
  442.  
  443. Rect    UpdateUpdateRects(LayerObj theLayer);
  444.     /*
  445.     **    ¶ The rect to be updated, plus lastUpdate/thisUpdate management.
  446.     **
  447.     **    INPUT:    theLayer    If nil is passed in, then no action is taken.
  448.     **
  449.     **    Return the rect that is to be updated, plus manage lastUpdate/thisUpdate
  450.     **    so that they apply to the next update. */
  451.  
  452. void    InvalLayer(LayerObj theLayer, Rect invalRect, Boolean includeLastUpdate);
  453.     /*
  454.     **    ¶ Invalidate a rectangle-worth of the layer.
  455.     **
  456.     **    INPUT:    theLayer            The layer to invalidate.  If nil is passed in, then no
  457.     **                                action is taken.
  458.     **            invalRect            The area to invalidate.
  459.     **            includeLastUpdate    If true, then union passed-in rect with last rect, thus
  460.     **                                giving a resulting inval area large enough to enclose the
  461.     **                                last position of an object being dragged.
  462.     **
  463.     **    Post a layer update rect.  The rect is unioned into the thisUpdate for the
  464.     **    layer and all layers below this layer.  If includeLastUpdate is true, then
  465.     **    the field includeLastUpdate is set true for each layer, as well.  This boolean
  466.     **    is used by the default update behavior to determine if the area last updated
  467.     **    should be updated again.  This makes animation effects easier in the the old
  468.     **    and new position for a player being moved are updated at the same time.  This
  469.     **    could be handled by hand by calculating the rect to be updated to include the
  470.     **    last position, but by passing includeLastUpdate as true, it is
  471.     **    handled automatically. */
  472.  
  473. void    SetLayerWorld(LayerObj theLayer);
  474.     /*
  475.     **    ¶ Set the port (and possibly GDevice) to the layer’s.
  476.     **
  477.     **    INPUT:    theLayer        If nil is passed in, then no action is taken.
  478.     **
  479.     **    This is a convenient call for setting a GWorld, while remembering what
  480.     **    the previous GWorld was.  This should be balanced with a call to
  481.     **    ResetLayerWorld.  A count of how many times this is called is kept
  482.     **    so that the old GWorld is cached only if SetLayerWorld is currently
  483.     **    in balance with ResetLayerWorld.  This keeps the oldest kept GWorld
  484.     **    from being overwritten by subsequent calls. */
  485.  
  486. void    ResetLayerWorld(LayerObj theLayer);
  487.     /*
  488.     **    ¶ Reset the port (and possibly GDevice) to before the SetLayerWorld call.
  489.     **
  490.     **    INPUT:    theLayer        If nil is passed in, then no action is taken.
  491.     **
  492.     **    This is used to undo a call to SetLayerWorld.  Calls to ResetLayerWorld
  493.     **    should be balanced with previous calls to SetLayerWorld. */
  494.  
  495. void    LockLayerWorld(LayerObj theLayer);
  496.     /*
  497.     **    ¶ Lock down the pixels for a layer's GWorld.
  498.     **
  499.     **    INPUT:    theLayer        If nil is passed in, then no action is taken.
  500.     **
  501.     **    This is a convenient way to lock down the pixels for a layer's GWorld.
  502.     **    A locked count is kept to make sure that the GWorld is locked only the
  503.     **    first time this is called.  Calls to LockLayerWorld will most likely
  504.     **    be balanced by calls to UnlockLayerWorld, but not necessarily.  It may
  505.     **    be desirable to keep a GWorld layer locked.  In this case, right after
  506.     **    creating the layer (and indirectly its GWorld), call LockLayerWorld.
  507.     **    This will initially lock it.  Subsequent calls would be balanced, and
  508.     **    therefore there will always be one more LockLayerWorld call than
  509.     **    UnlockLayerWorld calls.  This will keep it locked. */
  510.  
  511. void    UnlockLayerWorld(LayerObj theLayer);
  512.     /*
  513.     **    ¶ Unlock down the pixels for a layer's GWorld.
  514.     **
  515.     **    INPUT:    theLayer        If nil is passed in, then no action is taken.
  516.     **
  517.     **    This undoes what LockLayerWorld does.  Calls to UnlockLayerWorld will
  518.     **    generally be balanced with calls to LockLayerWorld. */
  519.  
  520. RgnHandle    ScreenDepthRegion(short depth);
  521.     /*
  522.     **    ¶ Returns region describing area of various screens of at least designated depth.
  523.     **
  524.     **    INPUT:    depth            Minimum screen depth necessary to add monitor to region.
  525.     **
  526.     **    This returns a region describing the area of the various screens that is at least as deep
  527.     **    as the value passed in.  So, if you want to find out what area of the screens has at least
  528.     **    an 8-pixel depth, pass in an 8, and the region returned will describe that area.  If you
  529.     **    want the screen area that is exactly 8 pixels deep, call this function with an 8, and then
  530.     **    call it again with a 9.  Diff out the region returned when 9 was passed in.  The remaining
  531.     **    area is the area that is exactly 8 pixels deep.  (Dispose of both regions when you are done
  532.     **    with them.) */
  533.  
  534. CIconHandle    ReadCIcon(short iconID);
  535.     /*
  536.     **    ¶ System 6&7-savvy GetCIcon call.
  537.     **
  538.     **    INPUT:    iconID            Resource ID of 'cicn' to get.
  539.     **
  540.     **    This function is for system 6/7 compatibility.  System 6 doesn't normally have color icon
  541.     **    support, and if you call the 'cicn' functions in system 6, you will get an unimplemented
  542.     **    trap error.  ReadCIcon calls the color QuickDraw trap GetCIcon if it is available, or it
  543.     **    simply calls GetResource/ReleaseResource if the trap isn't available.
  544.     **
  545.     **    __________
  546.     **
  547.     **    Also see:    DrawCIcon, DrawCIconNoMask, DrawCIconByDepth, KillCIcon. */
  548.  
  549. void        KillCIcon(CIconHandle icon);
  550.     /*
  551.     **    ¶ System 6&7-savvy DisposeCIcon call.
  552.     **
  553.     **    INPUT:    iconID            Resource ID of 'cicn' to dispose.
  554.     **
  555.     **    This call disposes of a 'cicn' handle gotten by calling ReadCicon.
  556.     **
  557.     **    __________
  558.     **
  559.     **    Also see:    DrawCIcon, DrawCIconNoMask, DrawCIconByDepth, ReadCIcon. */
  560.  
  561. void        DrawCIcon(CIconHandle icon, Rect destRect);
  562.     /*
  563.     **    ¶ System 6&7-savvy PlotCIcon call.
  564.     **
  565.     **    INPUT:    iconID            Resource ID of 'cicn' to plot.
  566.     **
  567.     **    This function calls PlotCIcon if it is available, or it dereferences the 1-bit deep bitmap
  568.     **    of the 'cicn' and does a CopyBits if it isn't.
  569.     **
  570.     **    __________
  571.     **
  572.     **    Also see:    DrawCIconNoMask, DrawCIconByDepth, KillCIcon, ReadCIcon. */
  573.  
  574. void        DrawCIconNoMask(CIconHandle icon, Rect destRect);
  575.     /*
  576.     **    ¶ System 6&7-savvy alternate PlotCIcon call.
  577.     **
  578.     **    INPUT:    iconID            Resource ID of 'cicn' to plot with no mask.
  579.     **            destRect        Location to plot 'cicn'.
  580.     **
  581.     **    This function calls PlotCIcon with a temporary mask of nothing masked if it is available,
  582.     **    or it dereferences the 1-bit deep bitmap of the 'cicn' and does a CopyMask if it isn't.
  583.     **
  584.     **    __________
  585.     **
  586.     **    Also see:    DrawCIcon, DrawCIconByDepth, KillCIcon, ReadCIcon. */
  587.  
  588. void        DrawCIconByDepth(CIconHandle icon, Rect destRect, short depth, Boolean useMask);
  589.     /*
  590.     **    ¶ System 6&7-savvy smart PlotCIcon call.
  591.     **
  592.     **    INPUT:    iconID            Resource ID of 'cicn' to plot by depth.
  593.     **            destRect        Location to plot 'cicn'.
  594.     **            depth            Depth to plot 'cicn'.
  595.     **            useMask            True is 'cicn' should be drawn with its mask.
  596.     **
  597.     **    This call does either a CopyBits or CopyMask of the correct part of the 'cicn' resource.
  598.     **    The correct part is determined by the depth.  If a specific depth of 1 is requested, then
  599.     **    the bitmap portion of the 'cicn' is plotted.  If a specific depth of greater than 1 is
  600.     **    requested, and the depth of the target is greater than 1, then the pixmap portion of the 
  601.     **    'cicn' is plotted.
  602.     **
  603.     **    __________
  604.     **
  605.     **    Also see:    DrawCIcon, DrawCIconNoMask, KillCIcon, ReadCIcon. */
  606.  
  607. #endif
  608.