home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 365.lha / VSnap / misc.c < prev    next >
C/C++ Source or Header  |  1990-04-10  |  3KB  |  118 lines

  1. #define SCREENTOP\
  2.    (screen->TopEdge << ((screen->ViewPort.Modes & LACE)? 0: 1))
  3.  
  4. IMPORT struct IntuitionBase *IntuitionBase;
  5. IMPORT struct MsgPort *Sharedport;
  6. IMPORT WORD Sharedrefs;
  7.  
  8. struct Screen *WhichScreen()
  9.     REGISTER struct Screen *screen;
  10.     Forbid();
  11.     screen = IntuitionBase->FirstScreen;
  12.     while (screen && IntuitionBase->MouseY < SCREENTOP) {
  13.         screen = screen->NextScreen;
  14.     }
  15.     if (screen == NULL) {     /* Shouldn't happen */
  16.         screen = IntuitionBase->ActiveScreen;
  17.     }
  18.     Permit();
  19.     return screen;
  20. }
  21.  
  22. struct Window *WhichWindow(screen)
  23. struct Screen *screen;
  24.     struct Layer *layer;
  25.     layer = (struct Layer *)WhichLayer(&screen->LayerInfo,
  26.       (LONG)screen->MouseX, (LONG)screen->MouseY);
  27.     if (layer) {
  28.         return (struct Window *)layer->Window;
  29.     } else {
  30.         return NULL;
  31.     }
  32. }
  33.  
  34. struct Window *opensharedwindow(nw)
  35. struct NewWindow *nw;
  36. {
  37.     struct Window *win;
  38.     struct Screen scr;
  39.  
  40.     if (Sharedport) {
  41.         nw->IDCMPFlags = NULL;
  42.     } else {
  43.         nw->IDCMPFlags = CLOSEWINDOW;
  44.     }
  45.     if (!GetScreenData(&scr, (LONG)sizeof(struct Screen), WBENCHSCREEN, NULL)) {
  46.         return NULL;     /* No WB */
  47.     }
  48.     if (nw->TopEdge+nw->Height > scr.Height) {
  49.         nw->TopEdge = scr.Height-nw->Height;
  50.     }
  51.     if (nw->LeftEdge+nw->Width > scr.Width) {
  52.         nw->LeftEdge = scr.Width-nw->Width;
  53.     }
  54.     if (nw->TopEdge < 0) {
  55.         nw->TopEdge = 0;
  56.     }
  57.     if (nw->LeftEdge < 0) {
  58.         nw->LeftEdge = 0;
  59.     }
  60.  
  61.     if (win = OpenWindow(nw)) {
  62.         if (Sharedport) {
  63.             win->UserPort = Sharedport;
  64.             ModifyIDCMP(win, CLOSEWINDOW);
  65.         } else {
  66.             Sharedport = win->UserPort;
  67.         }
  68.         ++Sharedrefs;
  69.     }
  70.     return(win);
  71. }
  72.  
  73.  
  74. VOID closesharedwindow(win)
  75. struct Window *win;
  76. {
  77.     Forbid();
  78.     win->UserPort = NULL;
  79.     ModifyIDCMP(win, GADGETUP);     /* NEVER occurs */
  80.     Permit();
  81.     CloseWindow(win);
  82.     --Sharedrefs;
  83.     if (Sharedrefs == 0 && Sharedport) {
  84.         DeletePort(Sharedport);
  85.         Sharedport = NULL;
  86.     }
  87. }
  88.  
  89. VOID FreePlanes(bm, width, height)
  90. struct BitMap *bm;
  91. LONG width, height;
  92.     SHORT i;
  93.     for (i=0; i < bm->Depth; i++) {
  94.         if (bm->Planes[i]) {
  95.             FreeRaster(bm->Planes[i], width, height);
  96.         }
  97.     }
  98. }
  99.  
  100. WORD AllocPlanes(bm, width, height)
  101. struct BitMap *bm;
  102. LONG width, height;
  103.     WORD i;
  104.     for (i=0; i < bm->Depth; i++) {
  105.         bm->Planes[i] = NULL;
  106.     }
  107.     for (i=0; i < bm->Depth; i++) {
  108.         if (!(bm->Planes[i] = AllocRaster(width, height))) {
  109.             return 0;
  110.         }
  111.     }
  112.     return 1;
  113. }
  114.