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/>.
18 #include "precompiled.h"
22 IGUITextOwner::IGUITextOwner() : m_GeneratedTextsValid(false)
26 IGUITextOwner::~IGUITextOwner()
28 for (SGUIText
* const& t
: m_GeneratedTexts
)
32 void IGUITextOwner::AddText(SGUIText
* text
)
34 m_GeneratedTexts
.push_back(text
);
37 void IGUITextOwner::HandleMessage(SGUIMessage
& Message
)
41 case GUIM_SETTINGS_UPDATED
:
42 // Everything that can change the visual appearance.
43 // it is assumed that the text of the object will be dependent on
44 // these. Although that is not certain, but one will have to manually
45 // change it and disregard this function.
46 // TODO Gee: (2004-09-07) Make sure this is all options that can affect the text.
47 if (Message
.value
== "size" || Message
.value
== "z" ||
48 Message
.value
== "absolute" || Message
.value
== "caption" ||
49 Message
.value
== "font" || Message
.value
== "textcolor" ||
50 Message
.value
== "buffer_zone")
52 m_GeneratedTextsValid
= false;
61 void IGUITextOwner::UpdateCachedSize()
63 // If an ancestor's size changed, this will let us intercept the change and
64 // update our text positions
66 IGUIObject::UpdateCachedSize();
67 m_GeneratedTextsValid
= false;
70 void IGUITextOwner::DrawText(size_t index
, const CColor
& color
, const CPos
& pos
, float z
, const CRect
& clipping
)
72 if (!m_GeneratedTextsValid
)
75 m_GeneratedTextsValid
= true;
78 ENSURE(index
< m_GeneratedTexts
.size() && "Trying to draw a Text Index within a IGUITextOwner that doesn't exist");
81 GetGUI()->DrawText(*m_GeneratedTexts
[index
], color
, pos
, z
, clipping
);
84 void IGUITextOwner::CalculateTextPosition(CRect
& ObjSize
, CPos
& TextPos
, SGUIText
& Text
)
87 GUI
<EVAlign
>::GetSetting(this, "text_valign", valign
);
89 // The horizontal Alignment is now computed in GenerateText in order to not have to
90 // loop through all of the TextCall objects again.
91 TextPos
.x
= ObjSize
.left
;
96 TextPos
.y
= ObjSize
.top
;
99 // Round to integer pixel values, else the fonts look awful
100 TextPos
.y
= floorf(ObjSize
.CenterPoint().y
- Text
.m_Size
.cy
/2.f
);
103 TextPos
.y
= ObjSize
.bottom
- Text
.m_Size
.cy
;
106 debug_warn(L
"Broken EVAlign in CButton::SetupText()");
111 bool IGUITextOwner::MouseOverIcon()