OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
uiconsole.h
1/*
2===========================================================================
3Copyright (C) 2024 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23#pragma once
24
25typedef void ( *consoleHandler_t )( const char *text );
26
27class item {
28public:
29 str string;
30 int lines;
31 int begins[ 10 ];
32 int breaks[ 10 ];
33 const UColor *pColor;
34
35 item();
36};
37
38inline
39item::item()
40{
41 lines = 0;
42
43 for( int i = 0; i < 10; i++ )
44 {
45 begins[ i ] = 0;
46 breaks[ i ] = 0;
47 }
48
49 pColor = NULL;
50}
51
52#define MAX_CONSOLE_ITEMS 300
53
54class UIConsole : public UIWidget {
55protected:
56 UList<str> m_history;
57 void *m_historyposition;
58 item m_items[MAX_CONSOLE_ITEMS];
59 str m_currentline;
60 UIVertScroll *m_scroll;
61 int m_firstitem;
62 int m_numitems;
63 size_t m_caret;
64 str m_completionbuffer;
65 bool m_refreshcompletionbuffer;
66 int m_cntcmdnumber;
67 int m_cntcvarnumber;
68 consoleHandler_t m_consolehandler;
69
70public:
71 CLASS_PROTOTYPE( UIConsole );
72
73protected:
74 int getFirstItem( void );
75 int getNextItem( int prev );
76 int getLastItem( void );
77 int AddLine( void );
78 void DrawBottomLine( void );
79 void AddHistory( void );
80
81 virtual void Print( Event *ev );
82 virtual void KeyEnter( void );
83
84public:
85 UIConsole();
86
87 void setConsoleHandler( consoleHandler_t handler );
88 void AddText( const char *text, const UColor *pColor );
89 void CalcLineBreaks( item& theItem );
90 void Clear( void );
91 void FrameInitialized( void ) override;
92 void Draw( void ) override;
93 void CharEvent( int ch ) override;
94 qboolean KeyEvent( int key, unsigned int time ) override;
95 void OnSizeChanged( Event *ev );
96};
97
98class UIFloatingConsole : public UIFloatingWindow {
99protected:
100 UIStatusBar *m_status;
101 SafePtr<UIConsole> m_console;
102 consoleHandler_t m_handler;
103 UColor m_consoleColor;
104 UColor m_consoleBackground;
105 float m_consoleAlpha;
106
107public:
108 CLASS_PROTOTYPE( UIFloatingConsole );
109
110 UIFloatingConsole();
111 ~UIFloatingConsole();
112
113 void FrameInitialized( void ) override;
114 void OnChildSizeChanged( Event *ev );
115 void AddText( const char *text, const UColor *pColor );
116 void setConsoleHandler( consoleHandler_t handler );
117 void Clear( void );
118 void OnClosePressed( Event *ev );
119 void setConsoleBackground( const UColor& color, float alpha );
120 void setConsoleColor( const UColor& color );
121};
122
123class UIDMConsole : public UIConsole {
124 qboolean m_bQuickMessageMode;
125 int m_iMessageMode;
126
127public:
128 CLASS_PROTOTYPE( UIDMConsole );
129
130private:
131 void KeyEnter( void ) override;
132
133public:
134 UIDMConsole();
135
136 void AddDMMessageText( const char *text, const UColor *pColor );
137 void Draw( void ) override;
138 qboolean KeyEvent( int key, unsigned int time ) override;
139 qboolean GetQuickMessageMode( void );
140 void SetQuickMessageMode( qboolean bQuickMessage );
141 int GetMessageMode( void );
142 void SetMessageMode( int iMode );
143};
144
145class UIFloatingDMConsole : public UIFloatingWindow {
146protected:
147 UIStatusBar *m_status;
148 SafePtr<UIDMConsole> m_console;
149 consoleHandler_t m_handler;
150 UColor m_consoleColor;
151 UColor m_consoleBackground;
152 float m_consoleAlpha;
153
154public:
155 CLASS_PROTOTYPE( UIFloatingDMConsole );
156
157 UIFloatingDMConsole();
158 ~UIFloatingDMConsole();
159
160 void FrameInitialized( void ) override;
161 void OnChildSizeChanged( Event *ev );
162 void AddText( const char *text, const UColor *pColor );
163 void AddDMMessageText( const char *text, const UColor *pColor );
164 void setConsoleHandler( consoleHandler_t handler );
165 void Clear( void );
166 void OnClosePressed( Event *ev );
167 void setConsoleBackground( const UColor& color, float alpha );
168 void setConsoleColor( const UColor& color );
169 qboolean GetQuickMessageMode( void );
170 void SetQuickMessageMode( qboolean bQuickMessage );
171 int GetMessageMode( void );
172 void SetMessageMode( int iMode );
173};
Definition listener.h:246
Definition safeptr.h:160
Definition ucolor.h:25
Definition uistatus.h:56
Definition uivertscroll.h:31
Definition ulist.h:36
Definition uiconsole.h:27
Definition str.h:77