Don't crash while in the lobby when receiving an error IQ stanza without an error...
[0ad.git] / source / gui / IGUITextOwner.h
blob2766a80fc95fe1eecfa35e8d4ec28db01da12f56
1 /* Copyright (C) 2015 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
19 GUI Object Base - Text Owner
21 --Overview--
23 Interface class that enhance the IGUIObject with
24 cached CGUIStrings. This class is not at all needed,
25 and many controls that will use CGUIStrings might
26 not use this, but does help for regular usage such
27 as a text-box, a button, a radio button etc.
29 --More info--
31 Check GUI.h
35 #ifndef INCLUDED_IGUITEXTOWNER
36 #define INCLUDED_IGUITEXTOWNER
38 #include "GUI.h"
40 /**
41 * Framework for handling Output text.
43 * @see IGUIObject
45 class IGUITextOwner : virtual public IGUIObject
47 public:
48 IGUITextOwner();
49 virtual ~IGUITextOwner();
51 /**
52 * Adds a text object.
54 void AddText(SGUIText* text);
56 /**
57 * @see IGUIObject#HandleMessage()
59 virtual void HandleMessage(SGUIMessage& Message);
61 /**
62 * @see IGUIObject#UpdateCachedSize()
64 virtual void UpdateCachedSize();
66 /**
67 * Draws the Text.
69 * @param index Index value of text. Mostly this will be 0
70 * @param color
71 * @param pos Position
72 * @param z Z value
73 * @param clipping Clipping rectangle, don't even add a parameter
74 * to get no clipping.
76 virtual void DrawText(size_t index, const CColor& color, const CPos& pos, float z, const CRect& clipping = CRect());
78 /**
79 * Test if mouse position is over an icon
81 virtual bool MouseOverIcon();
83 protected:
85 /**
86 * Setup texts. Functions that sets up all texts when changes have been made.
88 virtual void SetupText() = 0;
90 /**
91 * Whether the cached text is currently valid (if not then SetupText will be called by Draw)
93 bool m_GeneratedTextsValid;
95 /**
96 * Texts that are generated and ready to be rendered.
98 std::vector<SGUIText*> m_GeneratedTexts;
101 * Calculate the position for the text, based on the alignment.
103 void CalculateTextPosition(CRect& ObjSize, CPos& TextPos, SGUIText& Text);
106 #endif // INCLUDED_IGUITEXTOWNER