2004-06-02 22:40:07 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string>
|
|
|
|
#include <deque>
|
|
|
|
#include <map>
|
|
|
|
|
2004-06-16 17:42:48 +02:00
|
|
|
#include "res/unifont.h"
|
2004-06-02 22:40:07 +02:00
|
|
|
#include "ogl.h"
|
|
|
|
#include "lib.h"
|
|
|
|
#include "sdl.h"
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CCONSOLE_H
|
|
|
|
#define CCONSOLE_H
|
|
|
|
|
2004-07-11 17:07:38 +02:00
|
|
|
#define BUFFER_SIZE 256 // for text being typed into the console
|
|
|
|
#define MESSAGE_SIZE 1024 // for messages being printed into the console
|
2004-06-02 22:40:07 +02:00
|
|
|
|
|
|
|
typedef void(*fptr)(void);
|
|
|
|
|
|
|
|
class CConsole
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
float m_fX;
|
|
|
|
float m_fY;
|
|
|
|
|
|
|
|
float m_fHeight;
|
|
|
|
float m_fWidth;
|
|
|
|
|
2004-06-03 03:42:40 +02:00
|
|
|
// "position" in show/hide animation, how visible the console is (0..1).
|
|
|
|
// allows implementing other animations than sliding, e.g. fading in/out.
|
|
|
|
float m_fVisibleFrac;
|
2004-06-03 02:19:22 +02:00
|
|
|
|
2004-06-16 17:42:48 +02:00
|
|
|
std::map<std::wstring, fptr> m_mapFuncList;
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2004-06-16 17:42:48 +02:00
|
|
|
std::deque<std::wstring> m_deqMsgHistory;
|
|
|
|
std::deque<std::wstring> m_deqBufHistory;
|
2004-06-02 22:40:07 +02:00
|
|
|
|
|
|
|
int m_iMsgHistPos;
|
|
|
|
|
2004-06-16 17:42:48 +02:00
|
|
|
wchar_t* m_szBuffer;
|
2004-06-02 22:40:07 +02:00
|
|
|
int m_iBufferPos;
|
|
|
|
int m_iBufferLength;
|
|
|
|
|
|
|
|
bool m_bFocus;
|
2004-06-03 03:42:40 +02:00
|
|
|
bool m_bVisible; // console is to be drawn
|
|
|
|
bool m_bToggle; // show/hide animation is currently active
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2004-06-16 17:42:48 +02:00
|
|
|
void ToLower(wchar_t* szMessage, uint iSize = 0);
|
|
|
|
void Trim(wchar_t* szMessage, const wchar_t cChar = 32, uint iSize = 0);
|
2004-06-02 22:40:07 +02:00
|
|
|
|
|
|
|
void DrawHistory(void);
|
|
|
|
void DrawWindow(void);
|
|
|
|
void DrawBuffer(void);
|
|
|
|
void DrawCursor(void);
|
|
|
|
|
|
|
|
bool IsEOB(void) {return (m_iBufferPos == m_iBufferLength);}; //Is end of Buffer?
|
|
|
|
bool IsBOB(void) {return (m_iBufferPos == 0);}; //Is beginning of Buffer?
|
|
|
|
bool IsFull(void) {return (m_iBufferLength == BUFFER_SIZE);};
|
|
|
|
bool IsEmpty(void) {return (m_iBufferLength == 0);};
|
|
|
|
|
|
|
|
void InsertBuffer(void){InsertMessage(m_szBuffer);};
|
2004-06-16 17:42:48 +02:00
|
|
|
void ProcessBuffer(const wchar_t* szLine);
|
2004-06-02 22:40:07 +02:00
|
|
|
|
|
|
|
public:
|
2004-07-11 18:03:26 +02:00
|
|
|
CConsole();
|
2004-06-02 22:40:07 +02:00
|
|
|
~CConsole();
|
|
|
|
|
2004-07-11 18:03:26 +02:00
|
|
|
void SetSize(float X = 300, float Y = 0, float W = 800, float H = 600);
|
|
|
|
|
2004-06-02 22:40:07 +02:00
|
|
|
void Update(float DeltaTime);
|
|
|
|
|
|
|
|
void Render();
|
|
|
|
|
2004-06-16 17:42:48 +02:00
|
|
|
void InsertMessage(const wchar_t* szMessage, ...);
|
2004-06-21 18:29:47 +02:00
|
|
|
void InsertChar(const int szChar, const wchar_t cooked);
|
2004-06-02 22:40:07 +02:00
|
|
|
|
2004-06-16 17:42:48 +02:00
|
|
|
void SetBuffer(const wchar_t* szMessage, ...);
|
2004-06-02 22:40:07 +02:00
|
|
|
void FlushBuffer();
|
|
|
|
|
2004-06-16 17:42:48 +02:00
|
|
|
void RegisterFunc(fptr F, const wchar_t* szName);
|
2004-06-03 02:19:22 +02:00
|
|
|
|
|
|
|
bool IsActive() { return m_bVisible; }
|
2004-06-16 17:42:48 +02:00
|
|
|
|
|
|
|
int m_iFontHeight;
|
|
|
|
int m_iFontOffset; // distance to move up before drawing
|
2004-06-02 22:40:07 +02:00
|
|
|
};
|
|
|
|
|
2004-06-11 00:24:03 +02:00
|
|
|
// TODO MT: Better solution to character translation than 'const int cooked'? Anyone?
|
|
|
|
|
2004-06-09 15:55:01 +02:00
|
|
|
#endif
|
2004-06-11 00:24:03 +02:00
|
|
|
|