home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 1 / FFMCD01.bin / bbs / libdisks / d700t799 / disk793.lha / Snap / src.lha / src / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-15  |  3.7 KB  |  162 lines

  1. /* Auto: make "CCEXTRA=-wq -qf"
  2. */
  3.  
  4. #define SCREENTOP\
  5.    (screen->TopEdge << ((screen->ViewPort.Modes & LACE)? 0: 1))
  6.  
  7. IMPORT struct SnapRsrc *SnapRsrc;
  8. IMPORT struct IntuitionBase *IntuitionBase;
  9. IMPORT struct DiskFontBase *DiskfontBase;
  10.  
  11. struct Screen *WhichScreen()
  12. {
  13.     REGISTER struct Screen *screen;
  14.     REGISTER ULONG lock;
  15.  
  16.     lock = LockIBase(0);
  17.     screen = IntuitionBase->FirstScreen;
  18.     while (screen && IntuitionBase->MouseY < SCREENTOP) {
  19.         screen = screen->NextScreen;
  20.     }
  21.     if (screen == NULL) {     /* Shouldn't happen */
  22.         screen = IntuitionBase->ActiveScreen;
  23.     }
  24.     UnlockIBase(lock);
  25.     return screen;
  26. }
  27.  
  28. struct Window *WhichWindow(screen)
  29. struct Screen *screen;
  30. {
  31.     struct Layer *layer;
  32.     layer = (struct Layer *)WhichLayer(&screen->LayerInfo,
  33.       (LONG)screen->MouseX, (LONG)screen->MouseY);
  34.     if (layer) {
  35.         return (struct Window *)layer->Window;
  36.     } else {
  37.         return NULL;
  38.     }
  39. }
  40.  
  41. VOID FreePlanes(bm, width, height)
  42. struct BitMap *bm;
  43. LONG width, height;
  44. {
  45.     SHORT i;
  46.     for (i=0; i < bm->Depth; i++) {
  47.         if (bm->Planes[i]) {
  48.             FreeRaster(bm->Planes[i], width, height);
  49.         }
  50.     }
  51. }
  52.  
  53. WORD AllocPlanes(bm, width, height)
  54. struct BitMap *bm;
  55. LONG width, height;
  56. {
  57.     WORD i;
  58.     for (i=0; i < bm->Depth; i++) {
  59.         bm->Planes[i] = NULL;
  60.     }
  61.     for (i=0; i < bm->Depth; i++) {
  62.         if (!(bm->Planes[i] = AllocRaster(width, height))) {
  63.             return 0;
  64.         }
  65.         BltClear((char *)bm->Planes[i], RASSIZE(width, height), NULL);
  66.     }
  67.     return 1;
  68. }
  69.  
  70. VOID CacheWindow(struct Window *Win,
  71.                  LONG xoff, LONG yoff,
  72.                  SHORT fw, SHORT fh,
  73.                  struct TextFont *font)
  74. {
  75.     struct CacheWindow *cw;
  76.  
  77.     if (!(cw = Create(CacheWindow))) {
  78.         return;
  79.     }
  80.     cw->Window = Win;
  81.     cw->xoff = xoff;
  82.     cw->yoff = yoff;
  83.     cw->fw = fw;
  84.     cw->fh = fh;
  85.     cw->font = font;
  86.     AddHead((struct List *)&SnapRsrc->CachedWindows, (struct Node *)cw);
  87.     if (SnapRsrc->CacheSize > 0) {
  88.         --SnapRsrc->CacheSize;
  89.     } else {
  90.         cw = (struct CacheWindow *)RemTail((struct List *)&SnapRsrc->CachedWindows);
  91.         Kill(cw);
  92.     }
  93. }
  94.  
  95. VOID CacheSync(Font)
  96. struct TextFont *Font;
  97. {
  98.     struct CacheWindow *cw;
  99.     struct CacheWindow *safe;
  100.  
  101.     SAFEMAPLIST(&SnapRsrc->CachedWindows, struct CacheWindow *, cw, safe) {
  102.         if (cw->font == SnapRsrc->AlternateFont) {
  103.             Remove((struct Node *)cw);
  104.             Kill(cw);
  105.         }
  106.     }
  107. }
  108.  
  109. struct CacheWindow *GetCachedWindow(Screen, Win)
  110. struct Screen *Screen;
  111. struct Window *Win;
  112. {
  113.     struct CacheWindow *cw;
  114.  
  115.     MAPLIST(&SnapRsrc->CachedWindows, struct CacheWindow *, cw) {
  116.         if (cw->Window == Win) {
  117.             LONG LockVal = LockIBase(0L);
  118.             REGISTER struct Window *w = Screen->FirstWindow;
  119.             while (w && w != Win) {
  120.                 w = w->NextWindow;
  121.             }
  122.             UnlockIBase(LockVal);
  123.             if (!w) {
  124.                 return NULL;
  125.             }
  126.             Remove((struct Node *)cw);
  127.             AddHead((struct List *)&SnapRsrc->CachedWindows, (struct Node *)cw);
  128.             return cw;
  129.         }
  130.     }
  131.     return NULL;
  132. }
  133.  
  134. struct TextFont *SmartOpenFont(ta)
  135. struct TextAttr *ta;
  136. {
  137.     struct TextFont *MemF;
  138.     struct TextFont *DskF = NULL;
  139.  
  140.     if ((MemF = OpenFont(ta)) && ta->ta_YSize == MemF->tf_YSize) {
  141.         return MemF;
  142.     }
  143.  
  144.     if (DiskfontBase) {
  145.         DskF = OpenDiskFont(ta);
  146.     }
  147.  
  148.     if (!MemF) {
  149.         return DskF;
  150.     }
  151.     if (!DskF) {
  152.         return MemF;
  153.     }
  154.     if (abs(ta->ta_YSize - MemF->tf_YSize) <=
  155.         abs(ta->ta_YSize - DskF->tf_YSize)) {
  156.         CloseFont(DskF);
  157.         return MemF;
  158.     }
  159.     CloseFont(MemF);
  160.     return DskF;
  161. }
  162.