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

📄 textinput.h

📁 MudMaster 2000 的C++源码
💻 H
字号:
/************************************************************************************
	Copyright (c) 2000 Aaron O'Neil
	All rights reserved.

	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions
	are met:

		1) Redistributions of source code must retain the above copyright notice, 
				this list of conditions and the following disclaimer.
		2) Redistributions in binary form must reproduce the above copyright notice, 
				this list of conditions and the following disclaimer in the documentation
				and/or other materials provided with the distribution.
		3) Redistributions in binary form must reproduce the above copyright notice on
				program startup. Additional credits for program modification are acceptable
				but original copyright and credits must be visible at startup.
		4) You may charge a reasonable copying fee for any distribution of Mud Master. 
				You may charge any fee you choose for support of Mud Master. You may not 
				charge a fee for Mud Master itself.

  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
	IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
	OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
	IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
	INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
	DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
	THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
	(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
	THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

**************************************************************************************/

struct KEYBOARDCHAR;

class CTextInput : public CScreen
{
public:
	// nXPos, nYpos	Screen coordinates to draw control.
	// nWdith			Screen width of control.
	// wAttr				Foreground and background colors.
	// nMaxLen			Maximum number of characters allowed.
	CTextInput(int nXPos, int nYPos, int nWidth, WORD wAttr,
		int nMaxLen);
	CTextInput();

	// If the empty constructor is called, this function must
	// be called before using the control.
	void Init(int nXPos, int nYPos, int nWidth, WORD wAttr,
		int nMaxLen);

	// Moves the control to another spot on the screen.
	void Move(int nXPos, int nYpos, int nWidth);

	// Causes the control to redraw itself.
	void Redraw();

	void ControlColor(WORD wAttr);

	// Passed with default params will wait for a key in the
	// buffer and process it.  Or you can pass in a key to 
	// be processed.
	void ProcessKey(KEYBOARDCHAR kbch);

	// Adds a character to the input text.
	void InsertChar(unsigned char ch);

	// Returns true if the key passed in would be processed by
	// the control.  
	BOOL IsProcessedKey(KEYBOARDCHAR kbch);

	// Will return TRUE after the user has pressed enter.
	BOOL IsLineReady()		{ return(m_bLineReady); }
	void SetLineReady()		{ m_bLineReady = TRUE; }

	// Retrieves the text entered.
	void GetText(CString &strText);

	// Set the control to the text and calls Home.
	void SetText(const char *pszText);

	// Inserts text at the cursor position.
	void InsertText(const char *pszAdd);

	// Called when left arrow is pressed.
	void ArrowLeft();
	void ArrowRight();

	void Delete();

	void Home();
	void End();

	void ScrollLeft();
	void ScrollRight();

	void WordLeft();
	void WordRight();

	// Called when the users pressed the tab key.  It walks backwards
	// until it finds a space or the beginning of the input field, 
	// then looks up this text in the tab completion list.
	void TabList();

	int  GetYPos()					{ return(m_nYPos); }

	void SetFore(int nColor);
	int  GetFore()					{ return(m_nFore); }
	void SetBack(int nColor);
	int  GetBack()					{ return(m_nBack); }

	// Pass in a number from 0 to 7, returns the color attribute.
	WORD BackColorAttribute(int nColor);
	// Pass in a number from 0 to 15, returns the color attribute.
	WORD ForeColorAttribute(int nColor);

private:
	int m_nXPos, m_nYPos;
	int m_nWidth;
	int m_nMaxLen;
	int m_nMaxVisible;		// m_nWidth-1
	int m_nScrollPos;	// m_nXPos+m_nWidth-1
	int m_nFore;
	int m_nBack;

	// TRUE after enter has been pressed.
	BOOL m_bLineReady;

	// The text of the control.
	CString m_strText;

	// Index of cursor into text buffer.
	int m_nTextIndex;

	// TRUE by default.
	BOOL m_bInsert;

	// Used to keep track of where to cycle through the tab list when
	// tab is pressed multiple times.
	BOOL m_nTabPressed;
	// This is the original text used before the TAB key was pressed.
	CString m_strTabOriginal;
	// This is the word from the tab list that was used.
	CString m_strTabWord;
};

⌨️ 快捷键说明

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