⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ascscrn.cpp

📁 使用BorlandC++4.5编译的一个MUD客户端程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    const void * source = &_TextElement(Pos(0,source_row));
    memcpy(target, source, Width() * sizeof(char));

    // Move color info now (cross your fingers!)
    Pos source_pos(0,source_row);
    Pos target_pos(0,target_row);
    for (int i = 0; i < Width(); i++)
    {
        _ForegroundElement(target_pos) = _ForegroundElement(source_pos);
        source_pos.X() += 1;
        target_pos.X() += 1;
    };

}

// _ClearRows - quick and dirty
//
void AsciiScreen::_ClearRows(int top, int bottom)
{
    for (int i=top; i <= bottom; i++)
        _ClearRow(i);
}

// ClearRow - clears row to spaces and sets it to the current color!
void AsciiScreen::_ClearRow(int row)
{
    ASSERT(row >= 0 && row < Height(), "Row must be on screen");

    _Invalidate(Pos(0,row), Size(Width(),1));
    
    // Just set the row to all spaces
    memset(&_TextElement(Pos(0,row)), ' ', (Width() * sizeof(char)));

    int start = (row * Width());
    int end = start + Width();
    for (int i = start; i < end; i++)
    {
        ASSERT(i < (Width() * Height()), "Index past end of array?");
        ASSERT(i >= 0, "Negative array index not allowed");
        
        _foreground[i] = _cursorForeground;
    };
}

void AsciiScreen::_ClearScreen()
{
    // Initialize screen memory
    memset(_text, (int)' ', (Width() * Height() * sizeof(char)));

    // Initialize all screen colors
    for (int i=0; i < (Width() * Height()); i++)
        _foreground[i] = _cursorForeground;

    _Invalidate(Pos(0,0), Size(Width(),Height()));
}

void AsciiScreen::_ClearToEOL()
{
    int width = Width() - _cursor.X();
    memset(&_TextElement(_cursor), ' ', width * sizeof(char));

    _Invalidate(_cursor, Size(width,1));

    // Set Color
    int start = ((_cursor.Y() * Width()) + _cursor.X()) - 1;
    int end = ((_cursor.Y() + 1) * Width()) - 1;
    ASSERT(end < (Width() * Height()), "Index past end of array?");
    ASSERT(end >= 0, "Negative array index?");
    
    for (int i = start; i < end; i++)
        _foreground[i] = _cursorForeground;

}

void AsciiScreen::_EscapeSequence(EscapeSequence & esc)
{
    // We are assuming that the sequence is comeplete, etc.
    //
    // Note that screen locations are 1-indexed in the escape sequences,
    // so there's lots of "subtract one" here.
    switch (esc.Type())
    {
      case EscapeSequence::CMOVE:
        {
            Pos new_pos(esc.Parameter(1) - 1,  // Column
                        esc.Parameter(0) - 1); // Row

            if (IsOnScreen(new_pos)) // Ignore if off screen
            {
                _Invalidate(_cursor, Size(1,1));
                _cursor = new_pos;
                _Invalidate(_cursor, Size(1,1));
            };
        };
        break;
        
      case EscapeSequence::SCROLL: // Set scroll region
        _scrollRegionTop = esc.Parameter(0) - 1;
        _scrollRegionBottom = esc.Parameter(1) - 1;

        // Make sure the scroll region is on screen
        if (_scrollRegionTop < 0)
            _scrollRegionTop = 0;
        else if (_scrollRegionTop >= Height())
            _scrollRegionTop = Height() - 1;

        if (_scrollRegionBottom < 0)
            _scrollRegionBottom = 0;
        else if (_scrollRegionBottom >= Height())
            _scrollRegionBottom = Height() - 1;

        if (_scrollRegionBottom < _scrollRegionTop)
            _scrollRegionBottom = _scrollRegionTop;
        
        break;
        
      case EscapeSequence::REV_NEWLINE: // Scroll current region back one
        _ReverseNewLine();
        break;    
  
      case EscapeSequence::CLRSCR:
        _ClearScreen();
        _cursor.X() = 0;
        _cursor.Y() = 0;
        break;
        
      case EscapeSequence::CLREOL:
        _ClearToEOL();
        break;
        
      case EscapeSequence::ANSI_COLOR:
        _AnsiColor(esc);
        break;
        
      case EscapeSequence::UNKNOWN: // Unrecoginzed by parser
      case EscapeSequence::NONE:   // Error, not parsed correctly
      default:
        ASSERT(0, "Unexpected escape sequence");
        break; // Not reached
    };
}

// _IncrementPos - move cursor one space
//
// This automatically wraps the cursor if at eol, and scrolls the screen
// if it is the last point on the screen
void AsciiScreen::_IncrementPos()
{
    if ((_cursor.X() + 1) >= Width())
    {
        _Invalidate(_cursor, Size(1,1));
        _NewLine();
        _Invalidate(_cursor, Size(1,1)); 
    }
    else
    {
        _Invalidate(_cursor, Size(2,1)); // Invalidate two spaces
        _cursor.X() += 1;
    };
}

void AsciiScreen::_ReverseNewLine()
{
    _cursor.X() = 0;      // Wrap X of cursor

    // Either wrap Y or scroll
    if ((_cursor.Y() - 1) < _scrollRegionTop) // Need to scroll?
        _ScrollCurrentRegion(-1);
    else
        _cursor.Y() -= 1;
    
    ASSERT(IsOnScreen(_cursor), "Logic error moved cursor off screen");
}

// ------------------------------------------------------------------
// _CarriageReturn - cursor to column 0, no line feed.
//
void AsciiScreen::_CarriageReturn()
{
    if (0 != _cursor.X()) // Don't bother if already at col 0
    {
        _Invalidate(_cursor, Size(1,1)); // Invalidate old pos
        _cursor.X() = 0;
        _Invalidate(_cursor, Size(1,1)); // Invalidate new pos
    };
}

// ------------------------------------------------------------------
// _NewLine - wrap cursor
//
void AsciiScreen::_NewLine(int count)
{
    _cursor.X() = 0;      // Wrap X of cursor
    int scroll_count = 0; // Amount to scroll current screen

    while (count)
    {
        -- count;
        // Either wrap Y or scroll
        if (_cursor.Y() >= _scrollRegionBottom) // Need to scroll?
            ++ scroll_count;
        else
            _cursor.Y() += 1;
    };
    if (0 < scroll_count)
        _ScrollCurrentRegion(scroll_count);
    
    ASSERT(IsOnScreen(_cursor), "Cursor moved past bottom of screen");
}

// EOF //

@2.1log@Roll.@text@d3 4a6 4// $Id: ascscrn.cpp 1.5 1995/10/15 23:27:50 tsurace Beta tsurace $// $Log: ascscrn.cpp $// Revision 1.5  1995/10/15  23:27:50  tsurace// Added a comment.d8 3d149 1a149 1    // Hell, I give up, something's really wrong--lose datad172 2a173 2            if (put_me == '\r')        // Ignore carriage returns?                ; // do nothingd257 1a257 1    a485 5        _Invalidate(_cursor, Size(1,1));        _cursor.X() = esc.Parameter(1) - 1; // Column        _cursor.Y() = esc.Parameter(0) - 1; // Row                if (! IsOnScreen(_cursor)) // cursor is off screen?d487 9a495 2            _cursor.X() = 0;       // Reset the cursor to a safe location            _cursor.Y() = 0;a496 1        _Invalidate(_cursor, Size(1,1));d575 13@1.5log@Added a comment.@text@d3 5a7 2// $Id: ascscrn.cpp 1.4 1995/10/11 20:58:37 tsurace Exp tsurace $// $Log: ascscrn.cpp $@1.4log@Switched to my ASSERT macro.Fixed reverse-scroll bug that caused core (or ASSERT failure).Added try/catch blocks to stop memory leaks.@text@d3 1a3 1// $Id: ascscrn.cpp 1.3 1995/10/08 23:27:10 tsurace Exp tsurace $d5 5d197 5a201 1// Does not attempt to preserve the contents@1.3log@Added ansi (foreground) color support.@text@d3 5a7 2// $Id$// $Log$d14 1a14 1#include <assert.h>d18 1d63 2a64 2    assert (0 == bold || 1 == bold);   // Invalid parameters?    assert (color >= 0 && color <= 7);d104 2a105 2    assert(NULL != _invalidateFunc); // Bad pointer!    assert(NULL != _scrollFunc);d124 1a124 1    assert(IsOnScreen(pos)); // Is this position valid?a137 2    _inputBuffer.Append(c);     // Append string to bufferd142 2d181 1a181 1    assert(NULL != c); // Null pointer is illegald196 11a206 2    delete [] _text;    _text = new char[width * height];d208 3d212 2a213 1    _foreground = new COLORREF[width * height];d239 3a241 3    assert(bottom >= top); // Hey, this won't work!    assert(top >= 0);    assert(bottom < Height()); // Off screen?a245 4    // This is tricky - it lets me pretend bottom is one past the    // actual bottom of the scroll area    ++ bottom;    d251 1a251 1        if (amount > bottom - top)d259 1a259 1            for (i = top; (i + amount) < bottom; i++)d263 1a263 1            for (i = (bottom - amount); i < bottom; i++)d269 1a269 1        if ((-amount) > bottom - top)d276 1a276 1            for (i = bottom; (i + amount) > top; i--)d287 1a287 1        _ClearRows(top, bottom-1);d292 2a293 2        if (0 == _CallScrollFunc(top,bottom - 1,amount))            _Invalidate(Pos(0,top), Size(Width(),bottom-top));d381 2a382 2    assert(target_row >= 0 && target_row < Height());  // Off screen?    assert(source_row >= 0 && source_row < Height());d414 1a414 1    assert(row >= 0 && row < Height()); // Off screen?d425 2a426 2        assert(i < (Width() * Height())); // Out of bounds?        assert(i >= 0);d454 2a455 2    assert(end < (Width() * Height())); // Out of bounds?    assert(end >= 0);                   // Out of bounds?d474 6a479 1        assert(IsOnScreen(_cursor)); // Oops!d486 15a500 2        assert(_scrollRegionTop >= 0 && _scrollRegionTop < Height());        assert(_scrollRegionBottom >= 0 && _scrollRegionBottom < Height());d524 1a524 1        assert(0); // Oops!d558 1a558 1    assert(IsOnScreen(_cursor)); // Off Screen?d573 1a573 1        if ((_cursor.Y() + 1) > _scrollRegionBottom) // Need to scroll?d581 1a581 1    assert(IsOnScreen(_cursor)); // Off Screen?@1.2log@Added Resize function, reverse newline handling.@text@d3 3a5 1// Please note:  This module makes MS-Windoze calls  :}  I got lazy!d16 32a47 1// Temporaryd49 16d87 1d108 1a108 1    delete [] _text;d293 58a444 1    {d446 1a446 1    };d486 2a487 2      case EscapeSequence::BOLD_ON:        _cursorForeground = _boldForeground;a489 4      case EscapeSequence::BOLD_OFF:        _cursorForeground = _normalForeground;        break;@1.1log@Initial revision@text@d85 4d135 24d216 1a216 1            for (i = top; i < (bottom + amount); i--)d224 1a224 1        _ClearRows(top, bottom);d286 1a286 1    for (int i=top; i < bottom; i++)d300 1a300 1    int start = (row * Width()) - 1;a317 1    {d319 1a319 1    };d365 2a366 2      case EscapeSequence::SCR_REV: // Scroll current region back one        // Not implementedd412 13@

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -