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

📄 vt102em.hpp

📁 使用BorlandC++4.5编译的一个MUD客户端程序
💻 HPP
字号:
#ifndef VT102EM_HPP
#define VT102EM_HPP

// ------------------------------------------------------------------------
// $Id: vt102em.hpp 2.2 1995/10/30 18:28:46 tsurace Beta $
// $Log: vt102em.hpp $// Revision 2.2  1995/10/30  18:28:46  tsurace// Added debug toggle and console mode switch to system menu.//
// Revision 2.1  1995/10/24  15:52:51  tsurace
// Roll.
//
// Revision 1.5  1995/10/18  22:58:27  tsurace
// Made MY_SOCKET_LONG message publicly available.
//
// Revision 1.4  1995/10/11  21:25:35  tsurace
// Moved Global to global.hpp.
// Added error checking and return value to NewSocket.
//
// Revision 1.3  1995/10/08  23:29:54  tsurace
// Added code to force update faster when scrolling.
//
// (end of log)

#include <winsock.h>

#include "resids.hpp"
#include "ascscrn.hpp"
#include "units.hpp"

// WM_USER through 0x7FFF are ours to use
const long VT_SOCKET_MSG  = (WM_USER + 1); // Recieved on socket evts

// All system menu ids must be less than 0xF000, and will be masked
// out with 0xFFF0.
const long VT_SYSMENU_DEBUG   = (0xF000 - 0x10);
const long VT_SYSMENU_CONSOLE = (0xF000 - 0x20);

// -----------------------------------------------------------------
// vt102em.hpp - VT 102 emulator window class
//
// Author: Tom Surace
//
// This class is intended as a simple win32s interface to the
// VaporTalk program, when it is compiled with -DHARDCODE
//
class VT102Emulator
{
friend class Global; // Can call WndProc
  public:
    VT102Emulator(int nCmdShow);
    virtual ~VT102Emulator();

    // Window Management functions
    HWND Handle();
    BOOL Show(int nCmdShow);
    void Update();

    // These are called by VaporTalk
    const char * NewSocket (SOCKET s, long events); 
    virtual void Output(char * str, int len); // Write a string

    // These are called by the AsciiScreen
    void Invalidate(const Pos & pos, const Size & size);
    static void InvalidateStaticCB(const Pos & pos,
                                   const Size & size,
                                   void * this_ptr);
    
    int ScrollArea(int target, int source, int size);
    static int  ScrollAreaStaticCB(int target,
                                   int source,
                                   int size,
                                   void * this_ptr);

  protected:
    HFONT            _font;        // You may modify this
    COLORREF         _backgroundColor; // Registered with class, too
    COLORREF         _cursorColor; // Color of cursor
    COLORREF         _cursorBackground;
    HPEN             _cursorPen;   // Pen used to outline cursor
    DWORD            _lastPaintTickCount; // Tick count at last WM_PAINT event
    int              _forceUpdateSoon;   // If nonzero, try to update soon!
    Size             _fontSize;
    AsciiScreen      _screen;  // The screen object
    virtual void     _Paint(); // Called on expose event
    virtual void     _Size(WPARAM type, int width, int height);

    // This is called for all events that are not routed to the above functions
    // Classes that handle the message should return nonzero, and set the
    // value of return_value_ret to an appropriate value, otherwise they
    // should return zero.
    virtual int _Dispatch(UINT msg,
                          WPARAM wParam,
                          LPARAM lParam,
                          LRESULT & return_value_ret);

  private:
    HWND             _hWnd;            // Handle of this window

    void             _DoSocketEvent(int event, int error_code);
    LRESULT          _SysMenuCommand(WPARAM command);
    void             _InitScreen();    // Default initialization
    int              _initialized;     // 0 until constructed
    void             _GetTextArea(const Pos & pos, RECT & area) const;
    void             _PutText(HDC hdc, HRGN clip_reg);  // _Paint helper
    void             _PutTextOneLine(HDC hdc, int row); // _PutText helper
    void             _PutCursor(HDC hdc);               // _Paint helper
    void             _TextToDevice(Pos & pos) const;
    
    static void      _Register();      // Class registration
    static char      _szClassName[80]; // Class name

    // This is called ONLY by Global::WndProc
    LRESULT WndProc( UINT iMessage, WPARAM wParam, LPARAM lParam );

};

// >>>>> Inline Functions <<<<< //
inline BOOL VT102Emulator::Show(int nCmdShow)
{
    return ShowWindow(Handle(), nCmdShow);
}

inline HWND VT102Emulator::Handle()
{
    return _hWnd;
}

inline void VT102Emulator::Update()
{
    UpdateWindow(Handle());
}

// ------------------------------------------------------------------------
// _ScreenToDevice - Converts screen pos to window (pixel) coords
//
inline void VT102Emulator::_TextToDevice(Pos & pos) const
{
    pos.X() = pos.X() * _fontSize.Width();
    pos.Y() = pos.Y() * _fontSize.Height();
}

// ------------------------------------------------------------------------
// _GetTextArea - returns screen area occupied by text cell at 'pos'
inline void VT102Emulator::_GetTextArea(const Pos & pos, RECT & area) const
{
    area.left = pos.X() * _fontSize.Width();
    area.top = pos.Y() * _fontSize.Height();
    
    area.right = area.left + _fontSize.Width();   // One char area
    area.bottom = area.top + _fontSize.Height();
}

#endif // VT102EM_HPP

⌨️ 快捷键说明

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