OpenMoHAA 0.82.1
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
28{
29public:
30 str string;
31 int lines;
32 int begins[10];
33 int breaks[10];
34 const UColor *pColor;
35
36 item();
37};
38
39inline item::item()
40{
41 lines = 0;
42
43 for (int i = 0; i < 10; i++) {
44 begins[i] = 0;
45 breaks[i] = 0;
46 }
47
48 pColor = NULL;
49}
50
51#define MAX_CONSOLE_ITEMS 300
52
53class UIConsole : public UIWidget
54{
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
99{
100protected:
101 UIStatusBar *m_status;
102 SafePtr<UIConsole> m_console;
103 consoleHandler_t m_handler;
104 UColor m_consoleColor;
105 UColor m_consoleBackground;
106 float m_consoleAlpha;
107
108public:
109 CLASS_PROTOTYPE(UIFloatingConsole);
110
111 UIFloatingConsole();
112 ~UIFloatingConsole();
113
114 void FrameInitialized(void) override;
115 void OnChildSizeChanged(Event *ev);
116 void AddText(const char *text, const UColor *pColor);
117 void setConsoleHandler(consoleHandler_t handler);
118 void Clear(void);
119 void OnClosePressed(Event *ev);
120 void setConsoleBackground(const UColor& color, float alpha);
121 void setConsoleColor(const UColor& color);
122};
123
124class UIDMConsole : public UIConsole
125{
126 qboolean m_bQuickMessageMode;
127 int m_iMessageMode;
128
129public:
130 CLASS_PROTOTYPE(UIDMConsole);
131
132private:
133 void KeyEnter(void) override;
134
135public:
136 UIDMConsole();
137
138 void AddDMMessageText(const char *text, const UColor *pColor);
139 void Draw(void) override;
140 qboolean KeyEvent(int key, unsigned int time) override;
141 qboolean GetQuickMessageMode(void);
142 void SetQuickMessageMode(qboolean bQuickMessage);
143 int GetMessageMode(void);
144 void SetMessageMode(int iMode);
145};
146
147class UIFloatingDMConsole : public UIFloatingWindow
148{
149protected:
150 UIStatusBar *m_status;
151 SafePtr<UIDMConsole> m_console;
152 consoleHandler_t m_handler;
153 UColor m_consoleColor;
154 UColor m_consoleBackground;
155 float m_consoleAlpha;
156
157public:
158 CLASS_PROTOTYPE(UIFloatingDMConsole);
159
160 UIFloatingDMConsole();
161 ~UIFloatingDMConsole();
162
163 void FrameInitialized(void) override;
164 void OnChildSizeChanged(Event *ev);
165 void AddText(const char *text, const UColor *pColor);
166 void AddDMMessageText(const char *text, const UColor *pColor);
167 void setConsoleHandler(consoleHandler_t handler);
168 void Clear(void);
169 void OnClosePressed(Event *ev);
170 void setConsoleBackground(const UColor& color, float alpha);
171 void setConsoleColor(const UColor& color);
172 qboolean GetQuickMessageMode(void);
173 void SetQuickMessageMode(qboolean bQuickMessage);
174 int GetMessageMode(void);
175 void SetMessageMode(int iMode);
176};
Definition listener.h:246
Definition safeptr.h:160
Definition ucolor.h:26
Definition uistatus.h:64
Definition uivertscroll.h:33
Definition ulist.h:38
Definition uiconsole.h:28
Definition str.h:77