home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d534 / term.lha / Term / Source.LZH / termRaster.c < prev    next >
C/C++ Source or Header  |  1991-07-17  |  9KB  |  495 lines

  1. /* $Revision Header * Header built automatically - do not edit! *************
  2.  *
  3.  *    (C) Copyright 1990 by Olaf 'Olsen' Barthel & MXM
  4.  *
  5.  *    Name .....: Serial.c
  6.  *    Created ..: Saturday 02-Mar-91 18:30
  7.  *    Revision .: 0
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    02-Mar-91       Olsen           Created this file!
  12.  *
  13.  * $Revision Header ********************************************************/
  14.  
  15. #include "termGlobal.h"
  16.  
  17.     /* RasterMarkArea(SHORT Column,SHORT Line,SHORT Length):
  18.      *
  19.      *    Mark an area in the term Buffer window.
  20.      */
  21.  
  22. VOID
  23. RasterMarkArea(SHORT Column,SHORT Line,SHORT Length)
  24. {
  25.     STATIC SHORT OldColumn = -1,OldLine = -1,OldLength = -1;
  26.  
  27.     if(OldColumn != Column || OldLine != Line || OldLength != Length)
  28.     {
  29.         if(OldColumn != -1)
  30.             ClipBlit(RPort,0,0,RPort,OldColumn << 3,OldLine << 3,OldLength << 3,8,0x50);
  31.  
  32.         ClipBlit(RPort,0,0,RPort,Column << 3,Line << 3,Length << 3,8,0x50);
  33.     }
  34.  
  35.     OldColumn    = Column;
  36.     OldLine        = Line;
  37.     OldLength    = Length;
  38. }
  39.  
  40.     /* RasterClip():
  41.      *
  42.      *    Put a character raster portion into the clipboard.
  43.      */
  44.  
  45. VOID
  46. RasterClip(BYTE SingleChar,BYTE Xerox)
  47. {
  48.     struct IntuiMessage    *Massage;
  49.     ULONG             Code,Class;
  50.     BYTE             SkipLoop = FALSE;
  51.     LONG             ThisLine,ThisColumn,MyColumn,SomeColumn;
  52.     UBYTE            *TheLine;
  53.  
  54.         /* Remember initial mouse position. */
  55.  
  56.     ThisColumn    = Window -> MouseX >> 3;
  57.     ThisLine    = Window -> MouseY >> 3;
  58.  
  59.     if(ThisColumn <= LastColumn && ThisLine <= LastLine)
  60.     {
  61.         RasterMarkArea(-1,-1,-1);
  62.  
  63.             /* Find the approriate line and its length. */
  64.  
  65.         TheLine = &Raster[RasterWidth * ThisLine];
  66.  
  67.         if(SingleChar)
  68.         {
  69.             if(TheLine[ThisColumn] && TheLine[ThisColumn] != ' ')
  70.             {
  71.                 SerWrite(&TheLine[ThisColumn],1);
  72.  
  73.                 if(Xerox)
  74.                 {
  75.                     switch(Config . SendCR)
  76.                     {
  77.                         case CR_IGNORE:    break;
  78.  
  79.                         case CR_ASCR:    SerWrite("\r",1);
  80.                                 break;
  81.  
  82.                         case CR_ASCRLF:    SerWrite("\r\n",2);
  83.                                 break;
  84.                     }
  85.                 }
  86.             }
  87.  
  88.             return;
  89.         }
  90.  
  91.             /* Resonable dimensions? */
  92.  
  93.         if(ThisColumn <= LastColumn)
  94.         {
  95.             MyColumn = ThisColumn;
  96.  
  97.                 /* Loop until left mouse button is release. */
  98.  
  99.             while(!SkipLoop)
  100.             {
  101.                 WaitPort(Window -> UserPort);
  102.  
  103.                 while(Massage = (struct IntuiMessage *)GetMsg(Window -> UserPort))
  104.                 {
  105.                     Class    = Massage -> Class;
  106.                     Code    = Massage -> Code;
  107.  
  108.                     ReplyMsg(Massage);
  109.  
  110.                         /* We're finished! */
  111.  
  112.                     if(Class == IDCMP_MOUSEBUTTONS && Code == SELECTUP)
  113.                     {
  114.                         SkipLoop = TRUE;
  115.  
  116.                             /* Did we get a reasonable mouse
  117.                              * position?
  118.                              */
  119.  
  120.                         if(MyColumn != ThisColumn)
  121.                         {
  122.                                 /* Preserve right order of
  123.                                  * numbers.
  124.                                  */
  125.  
  126.                             if(MyColumn < ThisColumn)
  127.                             {
  128.                                 LONG Help;
  129.  
  130.                                 Help        = ThisColumn;
  131.                                 ThisColumn    = MyColumn;
  132.                                 MyColumn    = Help;
  133.                             }
  134.  
  135.                             RasterMarkArea(-1,-1,-1);
  136.  
  137.                                 /* Clip the contents of the line to
  138.                                  * the clipboard.
  139.                                  */
  140.  
  141.                             SaveClip(&TheLine[ThisColumn],MyColumn - ThisColumn);
  142.  
  143.                             if(Xerox)
  144.                             {
  145.                                 SerWrite(&TheLine[ThisColumn],MyColumn - ThisColumn);
  146.  
  147.                                 switch(Config . SendCR)
  148.                                 {
  149.                                     case CR_IGNORE:    break;
  150.  
  151.                                     case CR_ASCR:    SerWrite("\r",1);
  152.                                             break;
  153.  
  154.                                     case CR_ASCRLF:    SerWrite("\r\n",2);
  155.                                             break;
  156.                                 }
  157.                             }
  158.                         }
  159.  
  160.                         break;
  161.                     }
  162.  
  163.                         /* The mouse has moved. */
  164.  
  165.                     if(Class == IDCMP_MOUSEMOVE)
  166.                     {
  167.                         STATIC LONG OldColumn = ~0;
  168.  
  169.                             /* Determine new mouse position. */
  170.  
  171.                         SomeColumn = MyColumn;
  172.  
  173.                         MyColumn = Massage -> MouseX >> 3;
  174.  
  175.                         if((Massage -> MouseY >> 3) < ThisLine)
  176.                             MyColumn = 0;
  177.  
  178.                         if((Massage -> MouseY >> 3) > ThisLine)
  179.                             MyColumn = LastColumn + 1;
  180.  
  181.                             /* Don't redraw the line if nothing
  182.                              * has changed.
  183.                              */
  184.  
  185.                         if(OldColumn != MyColumn)
  186.                         {
  187.                             OldColumn = MyColumn;
  188.  
  189.                                 /* Reasonable position? */
  190.  
  191.                             if(MyColumn <= LastColumn + 1)
  192.                             {
  193.                                 if(MyColumn >= 0)
  194.                                 {
  195.                                         /* Highlight the selected
  196.                                          * area (invert).
  197.                                          */
  198.  
  199.                                     if(MyColumn != ThisColumn)
  200.                                     {
  201.                                         if(MyColumn < ThisColumn)
  202.                                             RasterMarkArea(MyColumn,ThisLine,ThisColumn - MyColumn);
  203.                                         else
  204.                                             RasterMarkArea(ThisColumn,ThisLine,MyColumn - ThisColumn);
  205.                                     }
  206.                                 }
  207.                             }
  208.                             else
  209.                                 MyColumn = SomeColumn;
  210.                         }
  211.                     }
  212.                 }
  213.             }
  214.         }
  215.     }
  216. }
  217.  
  218.     /* DeleteRaster():
  219.      *
  220.      *    Free the contents of the character raster.
  221.      */
  222.  
  223. VOID
  224. DeleteRaster()
  225. {
  226.     if(Raster)
  227.     {
  228.         FreeVec(Raster);
  229.  
  230.         Raster = NULL;
  231.     }
  232. }
  233.  
  234.     /* CreateRaster():
  235.      *
  236.      *    Create the character raster.
  237.      */
  238.  
  239. BYTE
  240. CreateRaster()
  241. {
  242.         /* Width of the screen (in characters). */
  243.  
  244.     RasterWidth    = Window -> Width >> 3;
  245.  
  246.         /* Height of the character raster. */
  247.  
  248.     RasterHeight    = Window -> Height >> 3;
  249.  
  250.         /* Allocate the raster. */
  251.  
  252.     if(Raster = (UBYTE *)AllocVec(RasterWidth * RasterHeight * 2,MEMF_PUBLIC|MEMF_CLEAR))
  253.         return(TRUE);
  254.     else
  255.         return(FALSE);
  256. }
  257.  
  258.     /* RasterEraseScreen(BYTE Mode):
  259.      *
  260.      *    Erase parts of the screen.
  261.      */
  262.  
  263. VOID
  264. RasterEraseScreen(BYTE Mode)
  265. {
  266.     SHORT First,Last;
  267.  
  268.     switch(Mode)
  269.     {
  270.         case 1:    First    = 0;
  271.             Last    = CursorY * RasterWidth + CursorX; 
  272.             break;
  273.  
  274.         case 2:    First    = 0;
  275.             Last    = (RasterHeight + 1) * RasterWidth - 1;
  276.             break;
  277.  
  278.         default:First    = CursorY * RasterWidth;
  279.             Last    = (RasterHeight + 1) * RasterWidth - 1;
  280.             break;
  281.     }
  282.  
  283.     memset(&Raster[First],' ',Last - First);
  284. }
  285.  
  286.     /* RasterEraseLine(BYTE Mode):
  287.      *
  288.      *    Erase parts of the current cursor line.
  289.      */
  290.  
  291. VOID
  292. RasterEraseLine(BYTE Mode)
  293. {
  294.     SHORT First,Last;
  295.  
  296.     switch(Mode)
  297.     {
  298.         case 1:    First    = CursorY * RasterWidth;
  299.             Last    = First + CursorX;
  300.             break;
  301.  
  302.         case 2:    First    = CursorY * RasterWidth;
  303.             Last    = First + RasterWidth - 1;
  304.             break;
  305.  
  306.         default:First    = CursorY * RasterWidth + CursorX;
  307.             Last    = (CursorY + 1) * RasterWidth - 1;
  308.             break;
  309.     }
  310.  
  311.     memset(&Raster[First],' ',Last - First);
  312. }
  313.  
  314.     /* RasterEraseCharacters(SHORT Chars):
  315.      *
  316.      *    Erase a number of characters in the current cursor
  317.      *    line.
  318.      */
  319.  
  320. VOID
  321. RasterEraseCharacters(SHORT Chars)
  322. {
  323.     SHORT i,First,Diff = RasterWidth - CursorX;
  324.     UBYTE *FirstPtr,*LastPtr;
  325.  
  326.     First = CursorY * RasterWidth + CursorX;
  327.  
  328.     FirstPtr = &Raster[First];
  329.     LastPtr = &Raster[First + Chars];
  330.  
  331.     i = 0;
  332.  
  333.     while(i++ < Diff)
  334.     {
  335.         *FirstPtr++ = *LastPtr;
  336.  
  337.         *LastPtr++ = ' ';
  338.     }
  339. }
  340.  
  341.     /* RasterClearLine(SHORT Lines):
  342.      *
  343.      *    Clear the current line.
  344.      */
  345.  
  346. VOID
  347. RasterClearLine(SHORT Lines)
  348. {
  349.     memset(&Raster[CursorY * RasterWidth],' ',Lines * RasterWidth);
  350. }
  351.  
  352.     /* RasterInsertLine(SHORT Lines):
  353.      *
  354.      *    Insert a number of lines at the current cursor line.
  355.      */
  356.  
  357. VOID
  358. RasterInsertLine(SHORT Lines)
  359. {
  360.     if(CursorY + Lines > RasterHeight)
  361.         RasterEraseScreen(0);
  362.     else
  363.     {
  364.         SHORT First,Last,i,Max = Lines * RasterWidth;
  365.         UBYTE *FirstPtr,*LastPtr;
  366.  
  367.         First    = (LastLine - Lines + 2) * RasterWidth - 1;
  368.         Last    = (LastLine + 2) * RasterWidth - 1;
  369.  
  370.         FirstPtr = &Raster[First];
  371.         LastPtr = &Raster[Last];
  372.  
  373.         i = 0;
  374.  
  375.         while(i++ < Max)
  376.             *LastPtr-- = *FirstPtr--;
  377.  
  378.         RasterClearLine(Lines);
  379.     }
  380. }
  381.  
  382.     /* RasterScrollRegion(BYTE Direction):
  383.      *
  384.      *    Scroll the contents of the character raster up/down.
  385.      */
  386.  
  387. VOID
  388. RasterScrollRegion(BYTE Direction)
  389. {
  390.     SHORT RasterTop,RasterBottom,RasterLines;
  391.  
  392.     if(UseRegion)
  393.     {
  394.         RasterTop    = Top;
  395.         RasterBottom    = Bottom;
  396.         RasterLines    = Bottom - Top;
  397.     }
  398.     else
  399.     {
  400.         RasterTop    = 0;
  401.         RasterBottom    = LastLine + 1;
  402.         RasterLines    = LastLine + 1;
  403.     }
  404.  
  405.     if(Direction < 0)
  406.     {
  407.         SHORT First,Last,i,Max = RasterLines * RasterWidth;
  408.         UBYTE *FirstPtr,*LastPtr;
  409.  
  410.         First    = (RasterTop + RasterLines    ) * RasterWidth - 1;
  411.         Last    = (RasterTop + RasterLines + 1) * RasterWidth - 1;
  412.  
  413.         FirstPtr = &Raster[First];
  414.         LastPtr = &Raster[Last];
  415.  
  416.         i = 0;
  417.  
  418.         while(i++ < Max)
  419.             *LastPtr-- = *FirstPtr--;
  420.  
  421.         memset(&Raster[RasterTop * RasterWidth],' ',RasterWidth);
  422.     }
  423.     else
  424.     {
  425.         SHORT First,Last,i,Max = RasterLines * RasterWidth;
  426.         UBYTE *FirstPtr,*LastPtr;
  427.  
  428.         First    = RasterTop * RasterWidth + RasterWidth;
  429.         Last    = RasterTop * RasterWidth;
  430.  
  431.         FirstPtr = &Raster[First];
  432.         LastPtr = &Raster[Last];
  433.  
  434.         i = 0;
  435.  
  436.         while(i++ < Max)
  437.             *LastPtr++ = *FirstPtr++;
  438.  
  439.         memset(&Raster[RasterLines * RasterWidth],' ',RasterWidth);
  440.     }
  441. }
  442.  
  443.     /* RasterShiftChar():
  444.      *
  445.      *    Shift the characters following the current cursor
  446.      *    position one character to the right.
  447.      */
  448.  
  449. VOID
  450. RasterShiftChar()
  451. {
  452.     SHORT i,First;
  453.     UBYTE *FirstPtr,*LastPtr;
  454.  
  455.     First = CursorY * RasterWidth;
  456.  
  457.     FirstPtr = &Raster[First + RasterWidth - 1];
  458.     LastPtr = &Raster[First + RasterWidth - 1 - 1];
  459.  
  460.     i = RasterWidth - 1;
  461.  
  462.     while(i-- > CursorX)
  463.         *FirstPtr-- = *LastPtr--;
  464. }
  465.  
  466.     /* RasterPutString(UBYTE *String,SHORT Length):
  467.      *
  468.      *    Put a string into the character raster.
  469.      */
  470.  
  471. VOID
  472. RasterPutString(UBYTE *String,SHORT Length)
  473. {
  474.     SHORT X = CursorX;
  475.  
  476.     if(Config . FontScale != SCALE_HALF)
  477.     {
  478.         if(X && Config . InsertChar)
  479.             X--;
  480.  
  481.         if(Length == 1)
  482.         {
  483.             if(X + 1 < RasterWidth)
  484.                 Raster[CursorY * RasterWidth + X] = String[0];
  485.         }
  486.         else
  487.         {
  488.             if(X + Length >= RasterWidth)
  489.                 Length = RasterWidth - X;
  490.  
  491.             CopyMem(String,&Raster[CursorY * RasterWidth + X],Length);
  492.         }
  493.     }
  494. }
  495.