Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / interfaces_manager / text.cpp
blobb72f3e9032c85faf25a85bc51a8dda2c4e6d7557
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program 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 Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "stdpch.h"
21 //////////////
22 // Includes //
23 //////////////
24 // Client
25 #include "text.h"
26 #include "interfaces_manager.h"
29 ////////////////
30 // Namespaces //
31 ////////////////
32 using namespace NL3D;
35 /////////////
36 // Externs //
37 /////////////
38 extern UTextContext *TextContext;
40 uint32 inin;
42 //-----------------------------------------------
43 // CText :
44 // Constructor.
45 //-----------------------------------------------
46 CText::CText(uint id)
47 : CControl(id)
49 init(ucstring(""));
50 }// CText //
52 //-----------------------------------------------
53 // CText :
54 // Constructor.
55 //-----------------------------------------------
56 CText::CText(uint id, float x, float y, float x_pixel, float y_pixel, const ucstring &text, const CPen &pen)
57 : CControl(id, x, y, x_pixel, y_pixel, 0.f, 0.f, 0.f, 0.f), CPen(pen)
59 init(text);
60 }// CText //
62 //-----------------------------------------------
63 // CText :
64 // Constructor.
65 //-----------------------------------------------
66 CText::CText(uint id, float x, float y, float x_pixel, float y_pixel, const ucstring &text, uint32 fontSize, CRGBA color, bool shadow)
67 : CControl(id, x, y, x_pixel, y_pixel, 0.f, 0.f, 0.f, 0.f), CPen(fontSize, color, shadow)
69 init(text);
70 }// CText //
72 //-----------------------------------------------
73 // init :
74 // Initialize the button (1 function called for all constructors -> easier).
75 //-----------------------------------------------
76 void CText::init(const ucstring &text)
78 calculateDisplay();
79 _Text = text;
81 this->text( text );
82 }// init //
85 //-----------------------------------------------
86 // display :
87 // Display the text.
88 //-----------------------------------------------
89 void CText::display()
91 // If the control is hide -> return
92 if(!_Show)
93 return;
95 /* TextContext->setShaded(_Shadow);
96 */ TextContext->setHotSpot(_TextHotSpot);
97 /* TextContext->setColor(_Color);
98 TextContext->setFontSize(_FontSize);
99 */ //TextContext->printAt(_X_Display, _Y_Display, _Text);
100 TextContext->printAt(_X_Display, _Y_Display, _Index);
102 }// display //
106 //-----------------------------------------------
107 // Get the Text.
108 //-----------------------------------------------
109 ucstring CText::text()
111 return _Text;
113 //-----------------------------------------------
114 // Set the Text.
115 //-----------------------------------------------
116 void CText::text(ucstring txt)
118 bool shadow;
119 uint32 fontSize;
121 // get the current text context param
122 shadow = TextContext->getShaded();
123 fontSize = TextContext->getFontSize();
125 _Text = txt;
127 TextContext->setShaded(_Shadow);
128 TextContext->setColor(_Color);
129 TextContext->setFontSize(_FontSize);
131 TextContext->erase( _Index );
133 _Index = TextContext->textPush( _Text );
134 _Info = TextContext->getStringInfo( _Index);
136 // restore old values
137 TextContext->setShaded(shadow);
138 TextContext->setFontSize(fontSize);
142 //-----------------------------------------------
143 // calculateDisplay :
144 // Calculate the Display X, Y, Width, Height.
145 //-----------------------------------------------
146 void CText::calculateDisplay()
148 uint32 w, h;
149 CInterfMngr::getWindowSize(w, h);
151 // Calculate the HotSpot.
152 calculateHS();
154 _X_Display = _X_Ref + _X*_W_Ref + _X_Pixel/w;
155 _Y_Display = _Y_Ref + _Y*_H_Ref + _Y_Pixel/h;
157 // Calculate the display Width and Height.
158 _W_Display = _Info.StringWidth / w;
159 _H_Display = _Info.StringHeight / h;
161 _W_Pixel = _Info.StringWidth;
162 _H_Pixel = _Info.StringHeight;
163 }// calculateDisplay //
165 //-----------------------------------------------
166 // calculateHS :
167 // Calculate the display position of the control in relation to the position of the control (Hot Spot).
168 //-----------------------------------------------
169 void CText::calculateHS()
171 switch(_HotSpot)
173 case HS_TL:
174 _TextHotSpot = UTextContext::BottomRight;
175 break;
176 case HS_TM:
177 _TextHotSpot = UTextContext::MiddleBottom;
178 break;
179 case HS_TR:
180 _TextHotSpot = UTextContext::BottomLeft;
181 break;
183 case HS_ML:
184 _TextHotSpot = UTextContext::MiddleRight;
185 break;
186 case HS_MM:
187 _TextHotSpot = UTextContext::MiddleMiddle;
188 break;
189 case HS_MR:
190 _TextHotSpot = UTextContext::MiddleLeft;
191 break;
193 case HS_BL:
194 _TextHotSpot = UTextContext::TopRight;
195 break;
196 case HS_BM:
197 _TextHotSpot = UTextContext::MiddleTop;
198 break;
199 case HS_BR:
200 _TextHotSpot = UTextContext::TopLeft;
201 break;
203 }// calculateHS //
206 //-----------------------------------------------
207 // fontSize :
208 // Set the font size.
209 //-----------------------------------------------
210 void CText::fontSize(uint32 fs)
212 _FontSize = fs;
213 text( _Text );
214 }// fontSize //
216 //-----------------------------------------------
217 // color :
218 // Set the pen color.
219 //-----------------------------------------------
220 void CText::color(CRGBA color)
222 _Color = color;
223 text( _Text );
224 }// color //
226 //-----------------------------------------------
227 // shadow:
228 // Set the shadow state.
229 //-----------------------------------------------
230 void CText::shadow(bool s)
232 _Shadow = s;
233 text( _Text );
234 }// shadow //