File: SagoTextBox.hpp

package info (click to toggle)
blockattack 2.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 9,992 kB
  • sloc: cpp: 26,060; pascal: 351; sh: 172; makefile: 15
file content (73 lines) | stat: -rw-r--r-- 2,778 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
Copyright (c) 2018 Poul Sander

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#ifndef SAGOTEXTBOX_HPP
#define SAGOTEXTBOX_HPP

#include "SagoDataHolder.hpp"
#include "SagoTextField.hpp"

namespace sago {

class SagoTextBox final {
public:
	SagoTextBox();
	~SagoTextBox();
	void SetHolder(const SagoDataHolder* holder);
	void SetText(const char* text);
	void SetText(const std::string& text);
	void SetColor(const SDL_Color& color);
	
	/**
	 * Set the name of the font. Must be known to the data holder.
	 * The name could for instance be "freeserif".
	 * @param fontName Name of the font as required by SagoDataHolder
	 */
	void SetFont(const char* fontName);
	void SetFontSize(int fontSize);
	void SetOutline(int outlineSize, const SDL_Color& color);
	/**
	 * Sets the max width to generate. SagoTextBox will insert line breaks to keep the width below this number.
	 * Outline is not included in the width: If you have a 2 pixels outline the rendere may go 2 pixels beyond.
	 * You will always need to generate at least one char per line. If max width is too low one char will be drawn per line even if it goes above max width.
	 * Setting this to 0 will disable the feature.
	 * @param width The maximum width before forcing a line break
	 */
	void SetMaxWidth(int width);
	const std::string& GetText() const;
	void Draw(SDL_Renderer* target, int x, int y, SagoTextField::Alignment alignment = SagoTextField::Alignment::left);
	void UpdateCache();
private:
	void AppendLineToCache(const std::string& text);
	void SplitAndAppendLineToCache(TTF_Font* font, const std::string& text);
	SagoTextBox(const SagoTextBox& orig) = delete;
	SagoTextBox& operator=(const SagoTextBox& base) = delete;
	struct SagoTextBoxData;
	SagoTextBoxData *data;
};

}  //namespace sago

#endif /* SAGOTEXTBOX_HPP */