home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / disk utilities / backup / backup_restore / backup_src_v3.20.lha / ScrollingWindows.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-22  |  3.7 KB  |  167 lines

  1. /* ScrollingWindows.c */
  2. /* 21 Mar 1996 20:04:25 */
  3.  
  4. #ifndef BACKUP_INCLUDE
  5. #include "IncludeAll.c"
  6. #endif
  7. #include "Backup.h"
  8. #include "Backup_proto.h"
  9.  
  10.  
  11. /* aus Backup_Window.c */
  12. extern APTR vi;                /* VisualInfo */
  13. extern struct DrawInfo *myDrawInfo;
  14. extern struct Screen *WBScreen;
  15.  
  16.  
  17. static struct RastPort *SW_GetRp(struct ScrollingWindow *sWin);
  18. static void SW_InternalLine(struct ScrollingWindow *sWin, char *TextLine, size_t Length,
  19.         short Line,
  20.         short FgColor, short BgColor, BOOL italic,
  21.         short Indent);
  22.  
  23.  
  24. static struct RastPort *SW_GetRp(struct ScrollingWindow *sWin)
  25. {
  26.     return sWin->Requester ? sWin->Requester->ReqLayer->rp : sWin->Host->RPort;
  27. }
  28.  
  29.  
  30. void SW_cls(struct ScrollingWindow *sWin)
  31. {
  32.     struct RastPort *rp = SW_GetRp(sWin);
  33.  
  34.     EraseRect(rp, sWin->Left, sWin->Top,
  35.         sWin->Left+sWin->Width, sWin->Top+sWin->Height);
  36. }
  37.  
  38.  
  39. /* Ab Cursorpos. bis Zeilenende löschen */
  40. void SW_ClrEol(struct ScrollingWindow *sWin)
  41. {
  42.     unsigned short xstart, ystart, xend, yend;
  43.     struct RastPort *rp = SW_GetRp(sWin);
  44.  
  45.     xstart = max(sWin->Left, min(sWin->LastX, sWin->Left+sWin->Width));
  46.     xend   = min(sWin->Left+sWin->Width, sWin->Left+sWin->Width);
  47.  
  48.     yend   = min(sWin->LastY + 2, sWin->Top+sWin->Height);
  49.     ystart = max(sWin->Top, min(yend - sWin->sFont->tf_YSize, sWin->Top+sWin->Height));
  50.  
  51.     if (yend > ystart && xend > xstart)
  52.         EraseRect(rp, xstart, ystart, xend, yend-1);
  53. }
  54.  
  55.  
  56. /* Ab Cursorpos. bis Schirmende löschen */
  57. void SW_ClrEos(struct ScrollingWindow *sWin)
  58. {
  59.     unsigned short ymin;
  60.  
  61.     SW_ClrEol(sWin);
  62.  
  63.     ymin = sWin->LastY + 2;
  64.  
  65.     if (ymin < sWin->Top + sWin->Height && ymin >= sWin->Top)
  66.         {
  67.         EraseRect(SW_GetRp(sWin), sWin->Left, ymin,
  68.             sWin->Left + sWin->Width,
  69.             sWin->Top + sWin->Height);
  70.         }
  71. }
  72.  
  73.  
  74. void SW_Scroll(struct ScrollingWindow *sWin, short Lines)
  75. {
  76.     struct RastPort *rp = SW_GetRp(sWin);
  77.  
  78.     SetBPen(rp, myDrawInfo->dri_Pens[BACKGROUNDPEN]);
  79.     SetDrMd(rp, JAM2);
  80.     ScrollRaster(rp,
  81.         0, Lines * sWin->sFont->tf_YSize,            // dx, dy
  82.         sWin->Left, 1 + sWin->Top + 2,                // xmin, ymin
  83.         sWin->Left + sWin->Width,                // xmax
  84.         1 + sWin->Top + sWin->Lines * sWin->sFont->tf_YSize + 1    // ymax
  85.         );
  86. }
  87.  
  88.  
  89. void SW_WindowLine(struct ScrollingWindow *sWin, char *TextLine,  size_t Length, short Line,
  90.         BOOL mark, BOOL Select, BOOL cMark, short Indent)
  91. {
  92.     SW_InternalLine(sWin, TextLine, Length, 
  93.         Line,
  94.         Select ? 2 : 1, mark ? 3 : 0, cMark,
  95.         Indent);
  96. }
  97.  
  98.  
  99. static void SW_InternalLine(struct ScrollingWindow *sWin, char *TextLine, size_t Length,
  100.         short Line,
  101.         short FgColor, short BgColor, BOOL italic,
  102.         short Indent)
  103. {
  104.     struct TextExtent tExt;
  105.     struct RastPort *rp;
  106.     ULONG n;
  107.     short Top;
  108.     const LeftBorder = 2;
  109.     const TopBorder = 2;
  110.  
  111.     if (Line < 0 || Line >= sWin->Lines)
  112.         return;
  113.     if (!sWin->Host)
  114.         return;
  115.  
  116.     rp = SW_GetRp(sWin);
  117.     Top = 1 + Line * sWin->sFont->tf_YSize;
  118.  
  119.     SetFont(rp, sWin->sFont);
  120.  
  121.     if (sWin->FirstColumn < Length)
  122.         {
  123.         size_t TotalLength;
  124.  
  125.         TextLine += sWin->FirstColumn;
  126.         TotalLength = Length;
  127.  
  128.         Move(rp, sWin->Left + LeftBorder + Indent,
  129.             sWin->Top + TopBorder + Top + sWin->sFont->tf_Baseline);
  130.  
  131.         n = TextFit(rp, TextLine, TotalLength, 
  132.             &tExt, NULL, 1, sWin->Width - LeftBorder - Indent, sWin->Height);
  133.  
  134.         SetAPen(rp, FgColor);
  135.         SetBPen(rp, BgColor);
  136.         Text(rp, TextLine, n);
  137.  
  138.         sWin->LastX = rp->cp_x;
  139.         }
  140.     else
  141.         {
  142.         sWin->LastX = sWin->Left + LeftBorder;
  143.         }
  144.     sWin->LastY = sWin->Top + TopBorder + Top + sWin->sFont->tf_YSize;
  145.  
  146.     SetAPen(rp, BgColor);
  147.  
  148.     if (Indent)
  149.         {
  150.         // vom linken Rand bis Indent auffüllen
  151.         RectFill(rp, sWin->Left + LeftBorder,
  152.             sWin->Top + TopBorder + Top,
  153.             sWin->Left + LeftBorder + Indent - 1,
  154.             sWin->LastY - 1);
  155.         }
  156.     /* Zeile bis zum rechten Rand auffüllen */
  157.     RectFill(rp, sWin->LastX,
  158.         sWin->Top + TopBorder + Top,
  159.         sWin->Left + sWin->Width - LeftBorder - 1,
  160.         sWin->LastY - 1);
  161.  
  162.     sWin->LastX = sWin->Left + sWin->Width - 1;
  163.     sWin->LastY -= 2;
  164. }
  165.  
  166.  
  167.