home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool_main.zip / ool / source / XLayer.CPP < prev    next >
C/C++ Source or Header  |  1998-04-06  |  2KB  |  101 lines

  1. #include "xgraphdv.h"
  2. #include "xlayer.h"
  3. #include <stdlib.h>
  4.  
  5. /*@
  6. @class XLayer
  7. @parent XObject
  8. @type overview
  9. @symbol _
  10. @remarks XLayer is a class which can store a large amount of graphic-objects.
  11. Call AddObject() to add objects to the layer, with Draw you can draw the content
  12. on a graphic device like XGraphicDevice or XPrinterDevice
  13. */
  14.  
  15.  
  16. /*@ XLayer::AddObject(const XGraphicObject * obj)
  17. @group Add/Remove objects
  18. @remarks Adds an object
  19. @parameters   XGraphicObject * the object to add
  20. */
  21. void XLayer::AddObject(const XGraphicObject * obj)
  22. {
  23.    listCount ++;
  24.    list = (XGraphicObject**) realloc( list, listCount * sizeof(void*));
  25.    list[listCount -1] = (XGraphicObject*) obj;
  26. }
  27.  
  28.  
  29. /*@ XLayer::RemoveObject(XGraphicObject * obj, const BOOL destroyObject)
  30. @group Add/Remove objects
  31. @remarks Removes an object
  32. @parameters
  33. XGraphicObject * the object to add
  34. <BR>
  35. BOOL destroyObject   TRUE=call delete, FALSE=dont destroy, default is TRUE
  36. */
  37. BOOL XLayer::RemoveObject(XGraphicObject * obj, const BOOL destroyObject)
  38. {
  39.    BOOL swap = FALSE;
  40.  
  41.    for(int i = 0; i < listCount; i++)
  42.    {
  43.       if(list[i] == obj)
  44.       {
  45.          swap = TRUE;
  46.          if(destroyObject)
  47.             delete list[i];
  48.       } /* end if */
  49.       if(swap && i < listCount - 1)
  50.          list[i] = list[i + 1];
  51.    } /* end for */
  52.    if(swap)
  53.       listCount -= 1;
  54.    return swap;
  55. }
  56.  
  57.  
  58. XGraphicObject * XLayer::FindObject(const LONG x, const LONG y, const XGraphicObject * searchBehind)
  59. {
  60. /*
  61.    LONG x1 = x;
  62.    LONG y1 = y;
  63.  
  64.    XGraphicObject *b;
  65.  
  66.    if (searchBehind)
  67.       b = searchBehind->next;
  68.    else
  69.       b = first;
  70.  
  71.    while (b)
  72.    {
  73.       if (b->HitTest(x1, y1) == TRUE)
  74.          return b;
  75.       b = b->next;
  76.    }
  77. */
  78.    return NULL;
  79. }
  80.  
  81.  
  82. /*@ XLayer::Empty(BOOL destroy)
  83. @group Add/Remove objects
  84. @remarks Removes all objects
  85. @parameters
  86. BOOL destroyAll   TRUE=call delete for all objects, FALSE=dont destroy, default is TRUE
  87. */
  88. void XLayer::Empty(const BOOL destroy)
  89. {
  90.    if(destroy)
  91.    {
  92.       for(int i = 0; i < listCount; i++)
  93.       {
  94.          delete list[i];
  95.       }
  96.    }
  97.    free(list);
  98.    list = NULL;
  99.    listCount = 0;
  100. }
  101.