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

📄 vt102em.hpp

📁 使用BorlandC++4.5编译的一个MUD客户端程序
💻 HPP
字号:
head	2.2;access;symbols;locks; strict;comment	@// @;2.2date	95.10.30.18.28.46;	author tsurace;	state Release;branches;next	2.1;2.1date	95.10.24.15.52.51;	author tsurace;	state Exp;branches;next	1.5;1.5date	95.10.18.22.58.27;	author tsurace;	state Beta;branches;next	1.4;1.4date	95.10.11.21.25.35;	author tsurace;	state Exp;branches;next	1.3;1.3date	95.10.08.23.29.54;	author tsurace;	state Exp;branches;next	1.2;1.2date	95.10.07.00.33.27;	author tsurace;	state Exp;branches;next	1.1;1.1date	95.10.05.18.33.58;	author tsurace;	state Exp;branches;next	;desc@Basic vt102 emulator (subset) class.@2.2log@Added debug toggle and console mode switch to system menu.@text@#ifndef VT102EM_HPP
#define VT102EM_HPP

// ------------------------------------------------------------------------
// $Id: vt102em.hpp 2.1 1995/10/24 15:52:51 tsurace Exp tsurace $
// $Log: vt102em.hpp $
// 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

@2.1log@Roll.@text@d5 4a8 4// $Id: vt102em.hpp 1.5 1995/10/18 22:58:27 tsurace Beta tsurace $// $Log: vt102em.hpp $// Revision 1.5  1995/10/18  22:58:27  tsurace// Made MY_SOCKET_LONG message publicly available.d10 3a25 1#include "keyev.hpp"d28 7a34 1const long MY_SOCKET_MSG  = (WM_USER + 1); // Recieved on socket evtsa82 1    virtual void     _KeyDown(const KeyEvent & ev);d98 1@1.5log@Made MY_SOCKET_LONG message publicly available.@text@d5 5a9 2// $Id: vt102em.hpp 1.4 1995/10/11 21:25:35 tsurace Exp tsurace $// $Log: vt102em.hpp $@1.4log@Moved Global to global.hpp.Added error checking and return value to NewSocket.@text@d5 1a5 1// $Id: vt102em.hpp 1.3 1995/10/08 23:29:54 tsurace Exp tsurace $d7 4d23 3a25 1//d30 3a32 4// This class is intended as a simple win32s interface to programs// that can run under vt102 emulation.  It is event-driven, so let's// hope that the programs can be adapted...@1.3log@Added code to force update faster when scrolling.@text@d5 5a9 2// $Id$// $Log$a11 2#include <stdlib.h>d41 1a41 1    void NewSocket (SOCKET s, long events); d81 2a82 1    a98 38class Global{  public:    static void Init(HINSTANCE _hInstance, HINSTANCE _hPrevInstance);    static int  MessageLoop();    static HINSTANCE Instance();    static HINSTANCE PrevInstance();    static LRESULT CALLBACK _export        WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam);  private:    static HINSTANCE _hInstance;       // Application instance    static HINSTANCE _hPrevInstance;};// string_id is the resource id of the message stringinline void scream_and_die(int string_id){    char title[20];    char message[256];    if (LoadString(Global::Instance(), IDS_FATALERROR, title, 20)        && LoadString(Global::Instance(), string_id, message, 256))    {        MessageBox(NULL, message, title, MB_ICONSTOP + MB_OK);    };    exit(EXIT_FAILURE);};// scream_and_die for freeform messagesinline void scream_and_die(char * msg){    char title[20];    if (LoadString(Global::Instance(), IDS_FATALERROR, title, 20))        MessageBox(NULL, msg, title, MB_ICONSTOP + MB_OK);    exit(EXIT_FAILURE);};a114 10inline HINSTANCE Global::Instance(){    return _hInstance;};inline HINSTANCE Global::PrevInstance(){    return _hPrevInstance;};a133 2void invalidate_func(Pos & pos, Size & size);@1.2log@Added several constants to manage screen redraw, cursor color.Added _Size() function.@text@d4 5a57 1    HBRUSH           _backgroundBrush; // Registered with class, tood62 1@1.1log@Initial revision@text@d54 4a57 2    HBRUSH           _cursorBrush; // Color of cursor    HPEN             _cursorPen;   // Cursor pend62 1d77 1@

⌨️ 快捷键说明

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