home *** CD-ROM | disk | FTP | other *** search
- /*
- ** termScroll.c
- **
- ** Support routines for optimized screen scrolling.
- **
- ** Copyright © 1990-1995 by Olaf `Olsen' Barthel
- ** All Rights Reserved
- */
-
- #include "termGlobal.h"
-
- /* ScrollLineRectFill():
- *
- * Fill a rectangular portion of the window raster with the help
- * of the scrolling information.
- */
-
- VOID __regargs
- ScrollLineRectFill(struct RastPort *RPort,WORD MinX,WORD MinY,WORD MaxX,WORD MaxY)
- {
- WORD BackPen;
-
- if(MinX >= MaxX || MinY >= MaxY)
- return;
-
- if(TextAttributeTable[Attributes] & ATTR_INVERSE)
- BackPen = FgPen;
- else
- BackPen = BgPen;
-
- if(BackPen)
- {
- LONG Start,Stop;
-
- if((Start = MinY / TextFontHeight) < ScrollLineFirst)
- ScrollLineFirst = Start;
-
- if((Stop = (MaxY + 1) / TextFontHeight - 1) > ScrollLineLast)
- ScrollLineLast = Stop;
-
- if(GetBitMapDepth(RPort -> BitMap) > 1)
- {
- if(UseMasking)
- {
- WORD Mask = BackPen,i;
-
- for(i = Start ; i <= Stop ; i++)
- {
- if(ScrollLines[i] . Width)
- Mask |= ScrollLines[i] . ColourMask;
- }
-
- Mask &= DepthMask;
-
- if(!Mask)
- return;
-
- for(i = Start ; i <= Stop ; i++)
- {
- ScrollLines[i] . Left = 0;
- ScrollLines[i] . Right = LastColumn + 1;
- ScrollLines[i] . Width = TextFontWidth;
- ScrollLines[i] . ColourMask = BackPen;
- }
-
- SetMask(RPort,Mask);
- }
- else
- {
- WORD i;
-
- for(i = Start ; i <= Stop ; i++)
- {
- ScrollLines[i] . Left = 0;
- ScrollLines[i] . Right = LastColumn + 1;
- ScrollLines[i] . Width = TextFontWidth;
- ScrollLines[i] . ColourMask = BackPen;
- }
- }
- }
-
- if(BackPen != ReadAPen(RPort))
- SetAPen(RPort,BackPen);
-
- RectFill(RPort,WindowLeft + MinX,WindowTop + MinY,WindowLeft + MaxX,WindowTop + MaxY);
-
- return;
- }
-
- if(GetBitMapDepth(RPort -> BitMap) > 1)
- {
- /* Is there anything on the screen at all? */
-
- if(ScrollLineFirst <= ScrollLineLast)
- {
- if(UseMasking)
- {
- WORD ScrollLineMask = 0,
- ScrollLineLeft = 32767,
- ScrollLineRight = 0,
- Temp,
- i;
-
- /* Determine screen colour mask. */
-
- for(i = MinY / TextFontHeight ; i <= MaxY / TextFontHeight ; i++)
- {
- if(ScrollLines[i] . Width)
- {
- if((Temp = ScrollLines[i] . Left * ScrollLines[i] . Width) < ScrollLineLeft)
- ScrollLineLeft = Temp;
-
- if((Temp = (ScrollLines[i] . Right * ScrollLines[i] . Width) - 1) > ScrollLineRight)
- ScrollLineRight = Temp;
-
- ScrollLineMask |= ScrollLines[i] . ColourMask;
- }
- }
-
- /* Wrap the bits. */
-
- ScrollLineMask &= DepthMask;
-
- /* Did we get a sensible colour? */
-
- if(ScrollLineMask && ScrollLineLeft <= ScrollLineRight)
- {
- /* Determine new left margin. */
-
- if(ScrollLineLeft > MinX)
- MinX = ScrollLineLeft;
-
- /* Determine new right margin. */
-
- if(ScrollLineRight < MaxX)
- MaxX = ScrollLineRight;
-
- /* Determine new top line margin. */
-
- if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
- MinY = Temp;
-
- /* Determine new bottom line margin. */
-
- if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
- MaxY = Temp;
-
- /* Set the colour mask. */
-
- SetMask(RPort,ScrollLineMask);
-
- /* Add margin for italics or boldface. */
-
- if(MaxX == ScrollLineRight)
- MaxX += FontRightExtend;
- }
- }
- else
- {
- WORD ScrollLineLeft = 32767,
- ScrollLineRight = 0,
- Temp,
- i;
-
- /* Determine screen colour mask. */
-
- for(i = MinY / TextFontHeight ; i <= MaxY / TextFontHeight ; i++)
- {
- if(ScrollLines[i] . Width)
- {
- if((Temp = ScrollLines[i] . Left * ScrollLines[i] . Width) < ScrollLineLeft)
- ScrollLineLeft = Temp;
-
- if((Temp = (ScrollLines[i] . Right * ScrollLines[i] . Width) - 1) > ScrollLineRight)
- ScrollLineRight = Temp;
- }
- }
-
- /* Did we get a sensible colour? */
-
- if(ScrollLineLeft <= ScrollLineRight)
- {
- /* Determine new left margin. */
-
- if(ScrollLineLeft > MinX)
- MinX = ScrollLineLeft;
-
- /* Determine new right margin. */
-
- if(ScrollLineRight < MaxX)
- MaxX = ScrollLineRight;
-
- /* Determine new top line margin. */
-
- if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
- MinY = Temp;
-
- /* Determine new bottom line margin. */
-
- if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
- MaxY = Temp;
-
- /* Add margin for italics or boldface. */
-
- if(MaxX == ScrollLineRight)
- MaxX += FontRightExtend;
- }
- }
- }
- }
-
- /* And clear the raster. */
-
- if(MinX < MaxX && MinY < MaxY)
- RectFill(RPort,WindowLeft + MinX,WindowTop + MinY,WindowLeft + MaxX,WindowTop + MaxY);
- }
-
- /* ScrollLineRaster():
- *
- * Scroll the window raster with the help
- * of the scrolling information.
- */
-
- VOID __regargs
- ScrollLineRaster(struct RastPort *RPort,WORD DeltaX,WORD DeltaY,WORD MinX,WORD MinY,WORD MaxX,WORD MaxY,BYTE Smooth)
- {
- WORD BackPen;
-
- if((!DeltaX && !DeltaY) || MinX >= MaxX || MinY >= MaxY)
- return;
-
- if(TextAttributeTable[Attributes] & ATTR_INVERSE)
- BackPen = FgPen;
- else
- BackPen = BgPen;
-
- if(BackPen)
- {
- if(GetBitMapDepth(RPort -> BitMap) > 1)
- {
- if(UseMasking)
- {
- WORD i,Mask = BackPen;
-
- for(i = MinY / TextFontHeight ; i <= MaxY / TextFontHeight ; i++)
- {
- if(ScrollLines[i] . Width)
- Mask |= ScrollLines[i] . ColourMask;
- }
-
- Mask &= DepthMask;
-
- if(!Mask)
- return;
-
- SetMask(RPort,Mask);
- }
-
- if(DeltaX)
- {
- if(!ScrollLines[CursorY] . Width)
- return;
- else
- {
- ScrollLines[CursorY] . Left = 0;
- ScrollLines[CursorY] . Right = (LastPixel + 1) / ScrollLines[CursorY] . Width;
-
- ScrollLines[CursorY] . ColourMask |= BackPen;
- }
- }
- else
- {
- WORD i,Lines = DeltaY / TextFontHeight,Size,Start;
-
- Size = (MaxY - MinY + 1) / TextFontHeight;
- Start = MinY / TextFontHeight;
-
- if(Lines < 0)
- {
- if(Size == -Lines)
- {
- for(i = 0 ; i < -Lines ; i++)
- {
- ScrollLines[Start + i] . Left = 0;
- ScrollLines[Start + i] . Right = LastColumn + 1;
- ScrollLines[Start + i] . ColourMask = BackPen;
- ScrollLines[Start + i] . Width = TextFontWidth;
- }
- }
- else
- {
- for(i = 1 ; i <= -Lines ; i++)
- ScrollLines[Start + Size - i] = ScrollLines[Start - Lines - i];
-
- for(i = 0 ; i < -Lines ; i++)
- {
- ScrollLines[Start + i] . Left = 0;
- ScrollLines[Start + i] . Right = LastColumn + 1;
- ScrollLines[Start + i] . ColourMask = BackPen;
- ScrollLines[Start + i] . Width = TextFontWidth;
- }
- }
- }
- else
- {
- if(Size == Lines)
- {
- for(i = 0 ; i < Size ; i++)
- {
- ScrollLines[Start + i] . Left = 0;
- ScrollLines[Start + i] . Right = LastColumn + 1;
- ScrollLines[Start + i] . ColourMask = BackPen;
- ScrollLines[Start + i] . Width = TextFontWidth;
- }
- }
- else
- {
- for(i = 0 ; i < Lines ; i++)
- ScrollLines[Start + i] = ScrollLines[Start + Lines + i];
-
- for(i = Lines ; i < Size ; i++)
- {
- ScrollLines[Start + i] . Left = 0;
- ScrollLines[Start + i] . Right = LastColumn + 1;
- ScrollLines[Start + i] . ColourMask = BackPen;
- ScrollLines[Start + i] . Width = TextFontWidth;
- }
- }
- }
- }
- }
-
- if(MUL_Y(ScrollLineFirst) > MinY)
- ScrollLineFirst = MinY / TextFontHeight;
-
- if(MaxY > MUL_Y(ScrollLineLast + 1) - 1)
- ScrollLineLast = (MaxY + 1) / TextFontHeight;
-
- MinX += WindowLeft;
- MaxX += WindowLeft;
-
- MinY += WindowTop;
- MaxY += WindowTop;
-
- if(BackPen != ReadBPen(RPort))
- SetBPen(RPort,BackPen);
-
- /* Smooth scrolling required? */
-
- if(Smooth && DeltaY)
- {
- WORD Lines,Extra;
-
- Lines = ABS(DeltaY);
- Extra = Lines & 1;
- Lines = Lines / 2;
-
- if(DeltaY > 0)
- {
- while(Lines--)
- {
- WaitTOF();
-
- ScrollRaster(RPort,0,2,MinX,MinY,MaxX,MaxY);
- }
-
- if(Extra)
- {
- WaitTOF();
-
- ScrollRaster(RPort,0,1,MinX,MinY,MaxX,MaxY);
- }
- }
- else
- {
- while(Lines--)
- {
- WaitTOF();
-
- ScrollRaster(RPort,0,-2,MinX,MinY,MaxX,MaxY);
- }
-
- if(Extra)
- {
- WaitTOF();
-
- ScrollRaster(RPort,0,-1,MinX,MinY,MaxX,MaxY);
- }
- }
- }
- else
- ScrollRaster(RPort,DeltaX,DeltaY,MinX,MinY,MaxX,MaxY);
-
- return;
- }
-
- if(GetBitMapDepth(RPort -> BitMap) > 1)
- {
- if(UseMasking)
- {
- WORD ScrollLineMask;
-
- /* Are we to scroll a line in horizontal direction? If so, use the
- * colour mask of the current line.
- */
-
- if(DeltaX)
- {
- /* Set the colour mask. */
-
- if(ScrollLineMask = ScrollLines[CursorY] . ColourMask & DepthMask)
- SetMask(RPort,ScrollLineMask);
- }
- else
- {
- /* Any data on screen worth scrolling? */
-
- if(ScrollLineFirst <= ScrollLineLast)
- {
- WORD Temp,First,Last,SaveMinY = MinY / TextFontHeight,SaveMaxY = MaxY / TextFontHeight,ScrollLineLeft = 32767,ScrollLineRight = 0,i;
-
- /* Reset colourmask. */
-
- ScrollLineMask = 0;
-
- /* Build both the colour mask and the margins. */
-
- for(i = MinY / TextFontHeight ; i <= MaxY / TextFontHeight ; i++)
- {
- if(ScrollLines[i] . Width)
- {
- if((Temp = ScrollLines[i] . Left * ScrollLines[i] . Width) < ScrollLineLeft)
- ScrollLineLeft = Temp;
-
- if((Temp = (ScrollLines[i] . Right * ScrollLines[i] . Width) - 1) > ScrollLineRight)
- ScrollLineRight = Temp;
-
- ScrollLineMask |= ScrollLines[i] . ColourMask;
- }
- }
-
- /* Wrap the bits. */
-
- ScrollLineMask &= DepthMask;
-
- /* Sensible results? */
-
- if(ScrollLineMask && ScrollLineLeft <= ScrollLineRight)
- {
- /* Determine new left margin. */
-
- if(ScrollLineLeft > MinX)
- MinX = ScrollLineLeft;
-
- /* Determine new right margin. */
-
- if(ScrollLineRight < MaxX)
- MaxX = ScrollLineRight;
-
- /* Scroll down or up? */
-
- if(DeltaY < 0)
- {
- /* So we are to scroll down, find the first
- * blank line if any.
- */
-
- if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
- MinY = Temp;
-
- /* Find the last blank lines if any. */
-
- if((Temp = MUL_Y(ScrollLineLast + 1) - DeltaY - 1) < MaxY)
- MaxY = Temp;
-
- /* Determine margins and the like... */
-
- Last = (MaxY + 1) / TextFontHeight;
- First = Last - ((MaxY - MinY + TextFontHeight + DeltaY) / TextFontHeight);
- Temp = (-DeltaY) / TextFontHeight;
-
- /* Move the scroll line info up. */
-
- for(i = Last - 1 ; i >= First ; i--)
- ScrollLines[i] = ScrollLines[i - Temp];
-
- /* Clear the remaining lines. */
-
- for(i = First - Temp ; i < First ; i++)
- {
- ScrollLines[i] . Left = 32767;
- ScrollLines[i] . Right = 0;
- ScrollLines[i] . ColourMask = 0;
- ScrollLines[i] . Width = 0;
- }
-
- /* Is the first line we were working
- * on the first line of the whole display?
- * If so, update the line marker.
- */
-
- if(!SaveMinY)
- ScrollLineFirst += Temp;
-
- /* Now take a look at the last line.
- * If the last line we were working
- * on is in fact the last line of the
- * display, update the line marker.
- */
-
- if(SaveMaxY == LastLine)
- {
- ScrollLineLast += Temp;
-
- if(ScrollLineLast > LastLine)
- ScrollLineLast = LastLine;
- }
- }
- else
- {
- /* So we are to scroll up, find the last
- * blank line if any.
- */
-
- if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
- MaxY = Temp;
-
- /* Find the first blank lines if any. */
-
- if((Temp = MUL_Y(ScrollLineFirst) - DeltaY) > MinY)
- MinY = Temp;
-
- /* Determine margins and the like... */
-
- First = MinY / TextFontHeight;
- Last = ((MaxY - MinY + TextFontHeight - DeltaY) / TextFontHeight);
- Temp = DeltaY / TextFontHeight;
-
- /* Move the scroll line info down. */
-
- for(i = First ; i < First + Last ; i++)
- ScrollLines[i] = ScrollLines[i + Temp];
-
- /* Clear the remaining lines. */
-
- for(i = First + Last ; i < First + Last + Temp ; i++)
- {
- ScrollLines[i] . Left = 32767;
- ScrollLines[i] . Right = 0;
- ScrollLines[i] . ColourMask = 0;
- ScrollLines[i] . Width = 0;
- }
-
- /* Decrease number of last line. */
-
- if(SaveMaxY == LastLine)
- {
- if(ScrollLineLast > Temp)
- ScrollLineLast -= Temp;
- else
- ScrollLineLast = 0;
- }
-
- /* Decrease number of first line. */
-
- if(!SaveMinY)
- {
- if(ScrollLineFirst > Temp)
- ScrollLineFirst -= Temp;
- else
- ScrollLineFirst = 0;
- }
- }
-
- /* Adapt possible changes in the lines for first and last line. */
-
- while(ScrollLineFirst < RasterHeight)
- {
- if(ScrollLines[ScrollLineFirst] . Left > ScrollLines[ScrollLineFirst] . Right)
- ScrollLineFirst++;
- else
- break;
- }
-
- while(ScrollLineLast > 0)
- {
- if(ScrollLines[ScrollLineLast] . Left > ScrollLines[ScrollLineLast] . Right)
- ScrollLineLast--;
- else
- break;
- }
-
- /* Set the colour mask. */
-
- SetMask(RPort,ScrollLineMask);
-
- /* Add margin for italics or boldface. */
-
- if(MaxX == ScrollLineRight)
- MaxX += FontRightExtend;
- }
- }
- }
- }
- else
- {
- /* Are we to scroll a line in horizontal direction? If so, use the
- * colour mask of the current line.
- */
-
- if(!DeltaX)
- {
- /* Any data on screen worth scrolling? */
-
- if(ScrollLineFirst <= ScrollLineLast)
- {
- WORD Temp,First,Last,SaveMinY = MinY / TextFontHeight,SaveMaxY = MaxY / TextFontHeight,ScrollLineLeft = 32767,ScrollLineRight = 0,i;
-
- /* Build both the colour mask and the margins. */
-
- for(i = MinY / TextFontHeight ; i <= MaxY / TextFontHeight ; i++)
- {
- if(ScrollLines[i] . Width)
- {
- if((Temp = ScrollLines[i] . Left * ScrollLines[i] . Width) < ScrollLineLeft)
- ScrollLineLeft = Temp;
-
- if((Temp = (ScrollLines[i] . Right * ScrollLines[i] . Width) - 1) > ScrollLineRight)
- ScrollLineRight = Temp;
- }
- }
-
- /* Sensible results? */
-
- if(ScrollLineLeft <= ScrollLineRight)
- {
- /* Determine new left margin. */
-
- if(ScrollLineLeft > MinX)
- MinX = ScrollLineLeft;
-
- /* Determine new right margin. */
-
- if(ScrollLineRight < MaxX)
- MaxX = ScrollLineRight;
-
- /* Scroll down or up? */
-
- if(DeltaY < 0)
- {
- /* So we are to scroll down, find the first
- * blank line if any.
- */
-
- if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
- MinY = Temp;
-
- /* Find the last blank lines if any. */
-
- if((Temp = MUL_Y(ScrollLineLast + 1) - DeltaY - 1) < MaxY)
- MaxY = Temp;
-
- /* Determine margins and the like... */
-
- Last = (MaxY + 1) / TextFontHeight;
- First = Last - ((MaxY - MinY + TextFontHeight + DeltaY) / TextFontHeight);
- Temp = (-DeltaY) / TextFontHeight;
-
- /* Move the scroll line info up. */
-
- for(i = Last - 1 ; i >= First ; i--)
- ScrollLines[i] = ScrollLines[i - Temp];
-
- /* Clear the remaining lines. */
-
- for(i = First - Temp ; i < First ; i++)
- {
- ScrollLines[i] . Left = 32767;
- ScrollLines[i] . Right = 0;
- ScrollLines[i] . Width = 0;
- }
-
- /* Is the first line we were working
- * on the first line of the whole display?
- * If so, update the line marker.
- */
-
- if(!SaveMinY)
- ScrollLineFirst += Temp;
-
- /* Now take a look at the last line.
- * If the last line we were working
- * on is in fact the last line of the
- * display, update the line marker.
- */
-
- if(SaveMaxY == LastLine)
- {
- ScrollLineLast += Temp;
-
- if(ScrollLineLast > LastLine)
- ScrollLineLast = LastLine;
- }
- }
- else
- {
- /* So we are to scroll up, find the last
- * blank line if any.
- */
-
- if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
- MaxY = Temp;
-
- /* Find the first blank lines if any. */
-
- if((Temp = MUL_Y(ScrollLineFirst) - DeltaY) > MinY)
- MinY = Temp;
-
- /* Determine margins and the like... */
-
- First = MinY / TextFontHeight;
- Last = ((MaxY - MinY + TextFontHeight - DeltaY) / TextFontHeight);
- Temp = DeltaY / TextFontHeight;
-
- /* Move the scroll line info down. */
-
- for(i = First ; i < First + Last ; i++)
- ScrollLines[i] = ScrollLines[i + Temp];
-
- /* Clear the remaining lines. */
-
- for(i = First + Last ; i < First + Last + Temp ; i++)
- {
- ScrollLines[i] . Left = 32767;
- ScrollLines[i] . Right = 0;
- ScrollLines[i] . Width = 0;
- }
-
- /* Decrease number of last line. */
-
- if(SaveMaxY == LastLine)
- {
- if(ScrollLineLast > Temp)
- ScrollLineLast -= Temp;
- else
- ScrollLineLast = 0;
- }
-
- /* Decrease number of first line. */
-
- if(!SaveMinY)
- {
- if(ScrollLineFirst > Temp)
- ScrollLineFirst -= Temp;
- else
- ScrollLineFirst = 0;
- }
- }
-
- /* Adapt possible changes in the lines for first and last line. */
-
- while(ScrollLineFirst < RasterHeight)
- {
- if(ScrollLines[ScrollLineFirst] . Left > ScrollLines[ScrollLineFirst] . Right)
- ScrollLineFirst++;
- else
- break;
- }
-
- while(ScrollLineLast > 0)
- {
- if(ScrollLines[ScrollLineLast] . Left > ScrollLines[ScrollLineLast] . Right)
- ScrollLineLast--;
- else
- break;
- }
-
- /* Add margin for italics or boldface. */
-
- if(MaxX == ScrollLineRight)
- MaxX += FontRightExtend;
- }
- }
- }
- }
- }
-
- /* And scroll the raster. */
-
- if(MinX < MaxX && MinY < MaxY)
- {
- MinX += WindowLeft;
- MaxX += WindowLeft;
-
- MinY += WindowTop;
- MaxY += WindowTop;
-
- /* Smooth scrolling required? */
-
- if(Smooth && DeltaY)
- {
- WORD Lines,Extra;
-
- Lines = ABS(DeltaY);
- Extra = Lines & 1;
- Lines = Lines / 2;
-
- if(DeltaY > 0)
- {
- while(Lines--)
- {
- WaitTOF();
-
- ScrollRaster(RPort,0,2,MinX,MinY,MaxX,MaxY);
- }
-
- if(Extra)
- {
- WaitTOF();
-
- ScrollRaster(RPort,0,1,MinX,MinY,MaxX,MaxY);
- }
- }
- else
- {
- while(Lines--)
- {
- WaitTOF();
-
- ScrollRaster(RPort,0,-2,MinX,MinY,MaxX,MaxY);
- }
-
- if(Extra)
- {
- WaitTOF();
-
- ScrollRaster(RPort,0,-1,MinX,MinY,MaxX,MaxY);
- }
- }
- }
- else
- ScrollRaster(RPort,DeltaX,DeltaY,MinX,MinY,MaxX,MaxY);
- }
- }
-
- /* ScrollLineEraseScreen(BYTE Mode):
- *
- * Erase a part of the screen.
- */
-
- VOID __regargs
- ScrollLineEraseScreen(BYTE Mode)
- {
- if(GetBitMapDepth(RPort -> BitMap) > 1)
- {
- WORD BackPen,i;
-
- if(TextAttributeTable[Attributes] & ATTR_INVERSE)
- BackPen = FgPen;
- else
- BackPen = BgPen;
-
- if(BackPen)
- {
- switch(Mode)
- {
- /* Erase from first line to current cursor line (inclusive). */
-
- case 1: ScrollLineFirst = CursorY;
-
- /* Reset the lines. */
-
- for(i = 0 ; i < CursorY ; i++)
- {
- ScrollLines[i] . Left = 0;
- ScrollLines[i] . Right = LastColumn + 1;
- ScrollLines[i] . ColourMask = BackPen;
- ScrollLines[i] . Width = TextFontWidth;
- }
-
- ScrollLines[CursorY] . Width = GetFontWidth();
- ScrollLines[CursorY] . Left = 0;
- ScrollLines[CursorY] . Right = (LastPixel + 1) / ScrollLines[CursorY] . Width;
- ScrollLines[CursorY] . ColourMask = BackPen;
-
- if(ScrollLineLast < CursorY)
- ScrollLineLast = CursorY;
-
- break;
-
- /* Erase entire screen. */
-
- case 2: for(i = 0 ; i < RasterHeight ; i++)
- {
- ScrollLines[i] . Left = 0;
- ScrollLines[i] . Right = LastColumn + 1;
- ScrollLines[i] . ColourMask = BackPen;
- ScrollLines[i] . Width = TextFontWidth;
- }
-
- ScrollLineFirst = 0;
- ScrollLineLast = RasterHeight - 1;
-
- break;
-
- /* Erase from current cursor position to end of screen. */
-
- default:for(i = CursorY + 1 ; i < RasterHeight ; i++)
- {
- ScrollLines[i] . Left = 0;
- ScrollLines[i] . Right = LastColumn + 1;
- ScrollLines[i] . ColourMask = BackPen;
- ScrollLines[i] . Width = TextFontWidth;
- }
-
- ScrollLines[CursorY] . Width = GetFontWidth();
- ScrollLines[CursorY] . Left = 0;
- ScrollLines[CursorY] . Right = (LastPixel + 1) / ScrollLines[CursorY] . Width;
- ScrollLines[CursorY] . ColourMask = BackPen;
-
- if(ScrollLineFirst > CursorY)
- ScrollLineFirst = CursorY;
-
- ScrollLineLast = RasterHeight - 1;
-
- break;
- }
-
- /* Adapt possible changes in the lines for first and last line. */
-
- while(ScrollLineFirst < RasterHeight)
- {
- if(ScrollLines[ScrollLineFirst] . Left > ScrollLines[ScrollLineFirst] . Right)
- ScrollLineFirst++;
- else
- break;
- }
-
- while(ScrollLineLast > 0)
- {
- if(ScrollLines[ScrollLineLast] . Left > ScrollLines[ScrollLineLast] . Right)
- ScrollLineLast--;
- else
- break;
- }
-
- return;
- }
-
- switch(Mode)
- {
- /* Erase from first line to current cursor line (inclusive). */
-
- case 1: ScrollLineFirst = CursorY;
-
- /* Reset the lines. */
-
- for(i = 0 ; i < CursorY ; i++)
- {
- ScrollLines[i] . Left = 32767;
- ScrollLines[i] . Right = 0;
- ScrollLines[i] . ColourMask = 0;
- ScrollLines[i] . Width = 0;
- }
-
- ScrollLines[CursorY] . Left = CursorX + 1;
-
- if(ScrollLines[CursorY] . Right < ScrollLines[CursorY] . Left)
- {
- ScrollLines[CursorY] . Left = 32767;
- ScrollLines[CursorY] . Right = 0;
- }
-
- break;
-
- /* Erase entire screen. */
-
- case 2: for(i = 0 ; i < RasterHeight ; i++)
- {
- ScrollLines[i] . Left = 32767;
- ScrollLines[i] . Right = 0;
- ScrollLines[i] . ColourMask = 0;
- ScrollLines[i] . Width = 0;
- }
-
- ScrollLineFirst = 32767;
- ScrollLineLast = 0;
-
- break;
-
- /* Erase from current cursor position to end of screen. */
-
- default:for(i = CursorY + 1 ; i < RasterHeight ; i++)
- {
- ScrollLines[i] . Left = 32767;
- ScrollLines[i] . Right = 0;
- ScrollLines[i] . ColourMask = 0;
- ScrollLines[i] . Width = 0;
- }
-
- if(CursorX)
- {
- ScrollLines[CursorY] . Right = CursorX;
-
- if(ScrollLines[CursorY] . Right < ScrollLines[CursorY] . Left)
- {
- ScrollLines[CursorY] . Left = 32767;
- ScrollLines[CursorY] . Right = 0;
- }
- }
- else
- {
- ScrollLines[CursorY] . Left = 32767;
- ScrollLines[CursorY] . Right = 0;
- }
-
- /* Cleared the entire screen? */
-
- if(CursorY)
- ScrollLineLast = CursorY;
- else
- {
- ScrollLineFirst = 32767;
- ScrollLineLast = 0;
- }
-
- break;
- }
-
- /* Adapt possible changes in the lines for first and last line. */
-
- while(ScrollLineFirst < RasterHeight)
- {
- if(ScrollLines[ScrollLineFirst] . Left > ScrollLines[ScrollLineFirst] . Right)
- ScrollLineFirst++;
- else
- break;
- }
-
- while(ScrollLineLast > 0)
- {
- if(ScrollLines[ScrollLineLast] . Left > ScrollLines[ScrollLineLast] . Right)
- ScrollLineLast--;
- else
- break;
- }
- }
- }
-
- /* ScrollLineEraseLine(BYTE Mode):
- *
- * Erase parts of the current cursor line.
- */
-
- VOID __regargs
- ScrollLineEraseLine(BYTE Mode)
- {
- if(GetBitMapDepth(RPort -> BitMap) > 1)
- {
- WORD BackPen;
-
- if(TextAttributeTable[Attributes] & ATTR_INVERSE)
- BackPen = FgPen;
- else
- BackPen = BgPen;
-
- if(BackPen)
- {
- switch(Mode)
- {
- /* Erase from left margin to current cursor position (inclusive). */
-
- case 1: ScrollLines[CursorY] . Left = 0;
-
- ScrollLines[CursorY] . ColourMask |= BackPen;
-
- break;
-
- /* Erase entire line. */
-
- case 2: ScrollLines[CursorY] . Width = GetFontWidth();
- ScrollLines[CursorY] . Left = 0;
- ScrollLines[CursorY] . Right = (LastPixel + 1) / ScrollLines[CursorY] . Width;
- ScrollLines[CursorY] . ColourMask = BackPen;
-
- break;
-
- /* Erase from current cursor position towards end of line. */
-
- default:if(CursorX)
- {
- if(!ScrollLines[CursorY] . Width)
- ScrollLines[CursorY] . Width = GetFontWidth();
-
- ScrollLines[CursorY] . Right = (LastPixel + 1) / ScrollLines[CursorY] . Width;
-
- ScrollLines[CursorY] . ColourMask |= BackPen;
- }
- else
- {
- ScrollLines[CursorY] . Width = GetFontWidth();
- ScrollLines[CursorY] . Left = 0;
- ScrollLines[CursorY] . Right = (LastPixel + 1) / ScrollLines[CursorY] . Width;
- ScrollLines[CursorY] . ColourMask = BackPen;
- }
-
- break;
- }
-
- /* Adapt possible changes in the lines for first and last line. */
-
- while(ScrollLineFirst < RasterHeight)
- {
- if(ScrollLines[ScrollLineFirst] . Left > ScrollLines[ScrollLineFirst] . Right)
- ScrollLineFirst++;
- else
- break;
- }
-
- while(ScrollLineLast > 0)
- {
- if(ScrollLines[ScrollLineLast] . Left > ScrollLines[ScrollLineLast] . Right)
- ScrollLineLast--;
- else
- break;
- }
-
- return;
- }
-
- switch(Mode)
- {
- /* Erase from left margin to current cursor position (inclusive). */
-
- case 1: ScrollLines[CursorY] . Left = CursorX + 1;
- break;
-
- /* Erase entire line. */
-
- case 2: ScrollLines[CursorY] . Left = 32767;
- ScrollLines[CursorY] . Right = 0;
-
- break;
-
- /* Erase from current cursor position towards end of line. */
-
- default:if(CursorX)
- ScrollLines[CursorY] . Right = CursorX;
- else
- {
- ScrollLines[CursorY] . Left = 32767;
- ScrollLines[CursorY] . Right = 0;
- }
-
- break;
- }
-
- /* Adapt possible changes in the lines for first and last line. */
-
- while(ScrollLineFirst < RasterHeight)
- {
- if(ScrollLines[ScrollLineFirst] . Left > ScrollLines[ScrollLineFirst] . Right)
- ScrollLineFirst++;
- else
- break;
- }
-
- while(ScrollLineLast > 0)
- {
- if(ScrollLines[ScrollLineLast] . Left > ScrollLines[ScrollLineLast] . Right)
- ScrollLineLast--;
- else
- break;
- }
- }
- }
-
- /* ScrollLineEraseCharacters(WORD Chars):
- *
- * Erase a number of characters in the current cursor line.
- */
-
- VOID __regargs
- ScrollLineEraseCharacters(WORD Chars)
- {
- if(GetBitMapDepth(RPort -> BitMap) > 1)
- {
- WORD BackPen;
-
- if(TextAttributeTable[Attributes] & ATTR_INVERSE)
- BackPen = FgPen;
- else
- BackPen = BgPen;
-
- /* Any characters to erase? */
-
- if(BackPen)
- {
- if(!ScrollLines[CursorY] . Width)
- ScrollLines[CursorY] . Width = GetFontWidth();
-
- ScrollLines[CursorY] . Left = 0;
- ScrollLines[CursorY] . Right = (LastPixel + 1) / ScrollLines[CursorY] . Width;
-
- ScrollLines[CursorY] . ColourMask |= BackPen;
- }
- else
- {
- if(ScrollLines[CursorY] . Right)
- ScrollLines[CursorY] . Right -= Chars;
- }
- }
- }
-
- /* ScrollLineShiftChar(WORD Size):
- *
- * Shift the characters following the current cursor position
- * Size characters to the right.
- */
-
- VOID __regargs
- ScrollLineShiftChar(WORD Size)
- {
- if(GetBitMapDepth(RPort -> BitMap) > 1)
- {
- WORD BackPen;
-
- if(TextAttributeTable[Attributes] & ATTR_INVERSE)
- BackPen = FgPen;
- else
- BackPen = BgPen;
-
- /* Any characters to scroll? */
-
- if(BackPen)
- {
- if(!ScrollLines[CursorY] . Width)
- ScrollLines[CursorY] . Width = GetFontWidth();
-
- ScrollLines[CursorY] . Left = 0;
- ScrollLines[CursorY] . Right = (LastPixel + 1) / ScrollLines[CursorY] . Width;
-
- ScrollLines[CursorY] . ColourMask |= BackPen;
- }
- else
- {
- if(ScrollLines[CursorY] . Right > 0)
- ScrollLines[CursorY] . Right += Size;
- }
- }
- }
-
- /* ScrollLinePutString(WORD Length):
- *
- * Update the line info according to the length of a string
- * to be printed.
- */
-
- VOID __regargs
- ScrollLinePutString(WORD Length)
- {
- if(GetBitMapDepth(RPort -> BitMap) > 1 && Length)
- {
- LONG Width;
-
- /* Which scale is the font we are currently using? */
-
- if(RasterAttr[CursorY] >= SCALE_ATTR_TOP2X)
- {
- /* Valid length? */
-
- if(CursorX + Length >= RasterWidth / 2)
- Length = (RasterWidth / 2) - CursorX;
-
- /* Double width. */
-
- Width = TextFontWidth * 2;
- }
- else
- {
- if(Config -> EmulationConfig -> FontScale == SCALE_HALF)
- {
- /* Valid length? */
-
- if(CursorX + Length >= RasterWidth * 2)
- Length = (RasterWidth * 2) - CursorX;
-
- /* Half width. */
-
- Width = TextFontWidth / 2;
- }
- else
- {
- /* Valid length? */
-
- if(CursorX + Length >= RasterWidth)
- Length = RasterWidth - CursorX;
-
- /* Normal width. */
-
- Width = TextFontWidth;
- }
- }
-
- /* Sensible value? */
-
- if(Length > 0)
- {
- if(UseMasking)
- {
- struct ScrollLineInfo *Alias = &ScrollLines[CursorY];
-
- /* Update line colour mask. */
-
- Alias -> ColourMask |= FgPen | BgPen;
-
- /* Update font scale. */
-
- Alias -> Width = Width;
-
- /* Set write mask (will affect Text() since it is called
- * after this routine has finished.
- */
-
- SetMask(RPort,Alias -> ColourMask);
-
- /* Update right margin. */
-
- if(CursorX < Alias -> Left)
- Alias -> Left = CursorX;
-
- /* Update left margin. */
-
- if(CursorX + Length > Alias -> Right)
- Alias -> Right = CursorX + Length;
-
- /* Update topmost line. */
-
- if(CursorY < ScrollLineFirst)
- ScrollLineFirst = CursorY;
-
- /* Update bottommost line. */
-
- if(CursorY > ScrollLineLast)
- ScrollLineLast = CursorY;
- }
- else
- {
- struct ScrollLineInfo *Alias = &ScrollLines[CursorY];
-
- /* Update font scale. */
-
- Alias -> Width = Width;
-
- /* Update right margin. */
-
- if(CursorX < Alias -> Left)
- Alias -> Left = CursorX;
-
- /* Update left margin. */
-
- if(CursorX + Length > Alias -> Right)
- Alias -> Right = CursorX + Length;
-
- /* Update topmost line. */
-
- if(CursorY < ScrollLineFirst)
- ScrollLineFirst = CursorY;
-
- /* Update bottommost line. */
-
- if(CursorY > ScrollLineLast)
- ScrollLineLast = CursorY;
- }
- }
- }
- }
-