git repos / blockattack-game

commit eb0258c8

sago007 · 2018-04-02 13:23
eb0258c847dcb4c304af5cb7511640cf73091626 patch · browse files
parent 0b8fb137d443484b642d2753014c43fd308ac38d

Updated the comments and made the assignment operator non generic to prvent accidental calling.

Changed files

M source/code/sago/SagoTextBox.hpp before
M source/code/sago/SagoTextField.cpp before
M source/code/sago/SagoTextField.hpp before
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};