git repos / blockattack-game

blame: source/code/sago/SagoTextBox.hpp

normal view · raw

55ea55dd sago007 2018-03-24 16:07 1
/*
55ea55dd sago007 2018-03-24 16:07 2
Copyright (c) 2018 Poul Sander
55ea55dd sago007 2018-03-24 16:07 3
55ea55dd sago007 2018-03-24 16:07 4
Permission is hereby granted, free of charge, to any person
55ea55dd sago007 2018-03-24 16:07 5
obtaining a copy of this software and associated documentation files
55ea55dd sago007 2018-03-24 16:07 6
(the "Software"), to deal in the Software without restriction,
55ea55dd sago007 2018-03-24 16:07 7
including without limitation the rights to use, copy, modify, merge,
55ea55dd sago007 2018-03-24 16:07 8
publish, distribute, sublicense, and/or sell copies of the Software,
55ea55dd sago007 2018-03-24 16:07 9
and to permit persons to whom the Software is furnished to do so,
55ea55dd sago007 2018-03-24 16:07 10
subject to the following conditions:
55ea55dd sago007 2018-03-24 16:07 11
55ea55dd sago007 2018-03-24 16:07 12
The above copyright notice and this permission notice shall be
55ea55dd sago007 2018-03-24 16:07 13
included in all copies or substantial portions of the Software.
55ea55dd sago007 2018-03-24 16:07 14
55ea55dd sago007 2018-03-24 16:07 15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
55ea55dd sago007 2018-03-24 16:07 16
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
55ea55dd sago007 2018-03-24 16:07 17
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
55ea55dd sago007 2018-03-24 16:07 18
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
55ea55dd sago007 2018-03-24 16:07 19
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
55ea55dd sago007 2018-03-24 16:07 20
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
55ea55dd sago007 2018-03-24 16:07 21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55ea55dd sago007 2018-03-24 16:07 22
SOFTWARE.
55ea55dd sago007 2018-03-24 16:07 23
*/
55ea55dd sago007 2018-03-24 16:07 24
55ea55dd sago007 2018-03-24 16:07 25
#ifndef SAGOTEXTBOX_HPP
55ea55dd sago007 2018-03-24 16:07 26
#define SAGOTEXTBOX_HPP
55ea55dd sago007 2018-03-24 16:07 27
55ea55dd sago007 2018-03-24 16:07 28
#include "SagoDataHolder.hpp"
55ea55dd sago007 2018-03-24 16:07 29
#include "SagoTextField.hpp"
55ea55dd sago007 2018-03-24 16:07 30
55ea55dd sago007 2018-03-24 16:07 31
namespace sago {
55ea55dd sago007 2018-03-24 16:07 32
55ea55dd sago007 2018-03-24 16:07 33
class SagoTextBox {
55ea55dd sago007 2018-03-24 16:07 34
public:
55ea55dd sago007 2018-03-24 16:07 35
	SagoTextBox();
55ea55dd sago007 2018-03-24 16:07 36
	virtual ~SagoTextBox();
55ea55dd sago007 2018-03-24 16:07 37
	void SetHolder(SagoDataHolder* holder);
55ea55dd sago007 2018-03-24 16:07 38
	void SetText(const char* text);
55ea55dd sago007 2018-03-24 16:07 39
	void SetColor(const SDL_Color& color);
55ea55dd sago007 2018-03-24 16:07 40
	void SetFont(const char* fontName);
55ea55dd sago007 2018-03-24 16:07 41
	void SetFontSize(int fontSize);
55ea55dd sago007 2018-03-24 16:07 42
	void SetOutline(int outlineSize, const SDL_Color& color);
55ea55dd sago007 2018-03-24 16:07 43
	/**
55ea55dd sago007 2018-03-24 16:07 44
	 * Sets the max width to generate. SagoTextBox will insert line breaks to keep the width below this number.
55ea55dd sago007 2018-03-24 16:07 45
	 * Outline is not included in the width: If you have a 2 pixels outline the rendere may go 2 pixels beyond.
55ea55dd sago007 2018-03-24 16:07 46
	 * 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.
55ea55dd sago007 2018-03-24 16:07 47
	 * Setting this to 0 will disable the feature.
55ea55dd sago007 2018-03-24 16:07 48
	 * @param width The maximum width before forcing a line break
55ea55dd sago007 2018-03-24 16:07 49
	 */
55ea55dd sago007 2018-03-24 16:07 50
	void SetMaxWidth(int width);
55ea55dd sago007 2018-03-24 16:07 51
	const std::string& GetText() const;
55ea55dd sago007 2018-03-24 16:07 52
	void Draw(SDL_Renderer* target, int x, int y);
55ea55dd sago007 2018-03-24 16:07 53
	void UpdateCache();
55ea55dd sago007 2018-03-24 16:07 54
private:
55ea55dd sago007 2018-03-24 16:07 55
	void AppendLineToCache(const std::string& text);
55ea55dd sago007 2018-03-24 16:07 56
	void SplitAndAppendLineToCache(TTF_Font* font, const std::string& text);
55ea55dd sago007 2018-03-24 16:07 57
	SagoTextBox(const SagoTextBox& orig) = delete;
55ea55dd sago007 2018-03-24 16:07 58
	SagoTextBox& operator=(const SagoTextBox& base) = delete;
55ea55dd sago007 2018-03-24 16:07 59
	struct SagoTextBoxData;
55ea55dd sago007 2018-03-24 16:07 60
	SagoTextBoxData *data;
55ea55dd sago007 2018-03-24 16:07 61
};
55ea55dd sago007 2018-03-24 16:07 62
55ea55dd sago007 2018-03-24 16:07 63
}  //namespace sago
55ea55dd sago007 2018-03-24 16:07 64
55ea55dd sago007 2018-03-24 16:07 65
#endif /* SAGOTEXTBOX_HPP */
55ea55dd sago007 2018-03-24 16:07 66
1970-01-01 00:00 67