1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #ifndef INFO_CONSOLE_H
4 #define INFO_CONSOLE_H
5 
6 #include "InputReceiver.h"
7 #include "System/float3.h"
8 #include "System/EventClient.h"
9 #include "System/Log/LogSinkHandler.h"
10 #include "System/Misc/SpringTime.h"
11 
12 #include <deque>
13 #include <string>
14 #include <list>
15 #include <boost/thread/recursive_mutex.hpp>
16 
17 class CInfoConsole: public CInputReceiver, public CEventClient, public ILogSink
18 {
19 public:
20 	CInfoConsole();
21 	virtual ~CInfoConsole();
22 
23 	void Update();
24 	void Draw();
25 	void PushNewLinesToEventHandler();
26 
27 	void RecordLogMessage(const std::string& section, int level,
28 			const std::string& text);
29 
WantsEvent(const std::string & eventName)30 	bool WantsEvent(const std::string& eventName) {
31 		return (eventName == "LastMessagePosition");
32 	}
33 	void LastMessagePosition(const float3& pos);
34 	const float3& GetMsgPos(const float3& defaultPos = ZeroVector);
GetMsgPosCount()35 	unsigned int GetMsgPosCount() const { return lastMsgPositions.size(); }
36 
37 	bool enabled;
38 
39 public:
40 	static const size_t maxLastMsgPos;
41 	static const size_t maxRawLines;
42 
43 	struct RawLine {
RawLineRawLine44 		RawLine(const std::string& text, const std::string& section, int level,
45 				int id)
46 			: text(text)
47 			, section(section)
48 			, level(level)
49 			, id(id)
50 			{}
51 		std::string text;
52 		std::string section;
53 		int level;
54 		int id;
55 	};
56 
57 	int GetRawLines(std::deque<RawLine>& copy);
58 
59 private:
60 	struct InfoLine {
61 		std::string text;
62 		spring_time timeout;
63 	};
64 
65 	std::list<float3> lastMsgPositions;
66 	std::list<float3>::iterator lastMsgIter;
67 
68 	std::deque<RawLine> rawData;
69 	std::deque<InfoLine> data;
70 
71 	size_t newLines;
72 	int rawId;
73 
74 	mutable boost::recursive_mutex infoConsoleMutex;
75 
76 	int lifetime;
77 	float xpos;
78 	float ypos;
79 	float width;
80 	float height;
81 	float fontScale;
82 	float fontSize;
83 
84 	size_t maxLines;
85 };
86 
87 #endif /* INFO_CONSOLE_H */
88