1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2013-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 // a buffer holding a log history
17 
18 #ifndef INC_C4LogBuf
19 #define INC_C4LogBuf
20 
21 // circular log buffer to holding line-wise log data
22 class C4LogBuffer
23 {
24 private:
25 	struct LineData
26 	{
27 		CStdFont *pFont; // line font
28 		DWORD dwClr;     // line clr
29 		bool fNewParagraph; // if set, this line marks a new paragraph (and is not the wrapped line of a previous par)
30 	};
31 
32 	char *szBuf;              // string buffer
33 	LineData *pLineDataBuf;   // line data buffer
34 	int iBufSize;             // size of string buffer
35 	int iFirstLinePos, iAfterLastLinePos; // current string buffer positions
36 	int iLineDataPos, iNextLineDataPos;   // current line data buffer positions
37 	int iMaxLineCount;        // max number of valid lines - size of line data buffer
38 	int iLineCount;           // number of valid lines in buffer
39 	int iLineBreakWidth;      // line breaking width
40 	char *szIndent;           // chars inserted as indent space
41 	bool fDynamicGrow;        // if true, lines are always added to the buffer. If false, the buffer is used circular and old lines removed
42 	bool fMarkup;             // if set, '|' is treated as linebreak
43 
44 	void GrowLineCountBuffer(size_t iGrowBy);
45 	void GrowTextBuffer(size_t iGrowBy);
46 	void DiscardFirstLine();  // discard oldest line in buffer
47 	void AppendSingleLine(const char *szLine, int iLineLength, const char *szIndent, CStdFont *pFont, DWORD dwClr, bool fNewParagraph); // append given string as single line
48 
49 public:
50 	C4LogBuffer(int iSize, int iMaxLines, int iLBWidth, const char *szIndentChars="    ", bool fDynamicGrow = false, bool fMarkup = true); // ctor
51 	~C4LogBuffer();           // dtor
52 
53 	void AppendLines(const char *szLine, CStdFont *pFont, DWORD dwClr, CStdFont *pFirstLineFont=nullptr);           // append message line to buffer; overwriting old lines if necessary
54 	const char *GetLine(int iLineIndex, CStdFont **ppFont, DWORD *pdwClr, bool *pNewParagraph) const; // get indexed line - negative indices -n return last-n'th-line
55 	void Clear();                              // clear all lines
56 
GetCount()57 	int GetCount() const { return iLineCount; }// retrieve number of valid lines in buffer
58 	void SetLBWidth(int iToWidth);
59 };
60 
61 #endif // C4LogBuf
62