diff --git a/source/code/sago/SagoTextBox.hpp b/source/code/sago/SagoTextBox.hpp index 025010d..5aeae4c 100644 --- a/source/code/sago/SagoTextBox.hpp +++ b/source/code/sago/SagoTextBox.hpp @@ -38,6 +38,12 @@ public: 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); diff --git a/source/code/sago/SagoTextField.cpp b/source/code/sago/SagoTextField.cpp index 62df1d4..6518899 100644 --- a/source/code/sago/SagoTextField.cpp +++ b/source/code/sago/SagoTextField.cpp @@ -83,7 +83,7 @@ SagoTextField::SagoTextField(SagoTextField&& o) noexcept { o.data = nullptr; } -SagoTextField& SagoTextField::operator=(const SagoTextField& base) { +SagoTextField& SagoTextField::CopyFrom(const SagoTextField& base) { ClearCache(); try { *data = *(base.data); diff --git a/source/code/sago/SagoTextField.hpp b/source/code/sago/SagoTextField.hpp index 962a924..ad24dc1 100644 --- a/source/code/sago/SagoTextField.hpp +++ b/source/code/sago/SagoTextField.hpp @@ -43,9 +43,17 @@ public: SagoTextField(); SagoTextField(SagoTextField&& o) noexcept; SagoTextField& operator=(const SagoTextField&& base) = delete; - SagoTextField& operator=(const SagoTextField& base); + SagoTextField& operator=(const SagoTextField& base) = delete; virtual ~SagoTextField(); /** + * This method creates a copy of a given font. + * The cache will not be copied. + * This is ALMOST like the "= operator" but given its own name to prevent implicit calling. + * @param base The object to copy from + * @return A reference to this object. + */ + SagoTextField& CopyFrom(const SagoTextField& base); + /** * Sets the data holder. This is MANDATORY * @param holder The data holder to fetch the fonts from */ @@ -55,10 +63,15 @@ public: * @param text The actual UTF-8 encoded text */ void SetText(const char* text); + /** + * Set the text to display. + * @param text The actual UTF-8 encoded 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); @@ -74,6 +87,14 @@ public: * @return The text */ const std::string& GetText() const; + /** + * A Shorthand for calling TTF_SizeUTF8 on the right font + * The size is measuered WITHOUT the outline! + * Will fail silently on error (except writing to stderr) and set w and h to 0 if they are not null. + * @param text The text to check the rendered size for + * @param w Pointer to an int where the width of the text will be stored. Maybe null. + * @param h Pointer to an int where the hight of the text will be stored. Maybe null. + */ void GetRenderedSize(const char* text, int* w = nullptr, int* h = nullptr); enum class Alignment { left = 0, right=1, center = 2 }; enum class VerticalAlignment { top = 0, center = 1};