home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / misc / dr.str / Source / Terminal.c < prev    next >
C/C++ Source or Header  |  1992-06-07  |  2KB  |  96 lines

  1. #include "StrangeGlove.h"
  2. #include "Terminal.h"
  3.  
  4. extern WindowPtr    gTermWindow;
  5. extern Boolean        gTerminal;
  6.  
  7. static int            curRow, curCol, maxRow, maxCol;
  8.  
  9.  
  10. /***** WriteTermWindow *****/
  11. void WriteTermWindow(char c)
  12. {
  13.     GrafPtr oldPort;
  14.     Point    curPen;
  15.     
  16.     GetPort(&oldPort);
  17.     SetPort(gTermWindow);
  18.     if ((c != 10) && (c != ESCAPECHAR))        /* 10 is some bad control-character */
  19.     {
  20.         GetPen(&curPen);
  21.         if (c == '\r')
  22.         {
  23.             if (curRow > maxRow)
  24.             {
  25.                 ScrollWindow();
  26.                 MoveTo(SIDEMARGIN, curRow);
  27.             }
  28.             else
  29.                 MoveTo(SIDEMARGIN, (curRow += ROWHEIGHT));
  30.         }
  31.         else
  32.         {
  33.             if (curPen.h > maxCol)
  34.             {
  35.                 if (curRow > maxRow)
  36.                 {
  37.                     ScrollWindow();
  38.                     MoveTo(SIDEMARGIN, curRow);
  39.                 }
  40.                 else
  41.                     MoveTo(SIDEMARGIN, (curRow += ROWHEIGHT));
  42.             }
  43.             DrawChar(c);
  44.         }
  45.     }
  46.     SetPort(oldPort);
  47. }
  48.  
  49.  
  50. /***** ScrollWindow *****/
  51. ScrollWindow()
  52. {
  53.     RgnHandle    tempRgn;
  54.     
  55.     tempRgn = NewRgn();
  56.     ScrollRect(&gTermWindow->portRect, HORIZONTAL_OFFSET, -ROWHEIGHT, tempRgn);
  57.     DisposeRgn(tempRgn);
  58. }
  59.  
  60.  
  61. /***** StartTerm *****/
  62. StartTerm()
  63. {
  64.     Rect    termRect;
  65.  
  66.     gTerminal = TRUE;
  67.  
  68.     SetPort(gTermWindow);
  69.     
  70.     termRect = gTermWindow->portRect;
  71.     maxRow = termRect.bottom - termRect.top - (ROWHEIGHT + BOTTOM_MARGIN);
  72.     maxCol = termRect.right - termRect.left - (2 * SIDEMARGIN);
  73.     curRow = STARTROW;
  74.     curCol = SIDEMARGIN;
  75.     
  76.     TextFont(monaco);
  77.     TextSize(TEXT_FONT_SIZE);
  78.     
  79.     MoveTo(SIDEMARGIN, STARTROW);
  80.     
  81.     ShowWindow(gTermWindow);
  82.     SelectWindow(gTermWindow);
  83.     AdjustTerminalMenu();
  84. }
  85.  
  86.  
  87. /***** StopTerm *****/
  88. StopTerm()
  89. {
  90.     gTerminal = FALSE;
  91.     HideWindow(gTermWindow);
  92.     AdjustTerminalMenu();
  93. }
  94.  
  95.  
  96.