Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / interfaces_manager / interfaces_manager.cpp
blobdafad83042df9bdc3ff1f18e18658a50ce5dd629
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/>.
19 #include "stdpch.h"
22 //////////////
23 // Includes //
24 //////////////
25 // Misc.
26 #include "nel/misc/path.h"
27 // 3D Interface.
28 #include "nel/3d/u_driver.h"
29 // Client.
30 #include "interfaces_manager.h"
31 #include "interf_script.h"
32 // Std.
33 #include <fstream>
36 ///////////
37 // Using //
38 ///////////
39 using namespace NLMISC;
40 using namespace NL3D;
41 using namespace std;
44 /////////////
45 // Externs //
46 /////////////
47 extern UDriver *Driver;
50 ////////////
51 // Global //
52 ////////////
54 CInterfMngr::TMapCtrls CInterfMngr::_Ctrls;
55 CInterfMngr::TMapTexts CInterfMngr::_Texts;
56 CInterfMngr::TMapTextures CInterfMngr::_Textures;
57 CInterfMngr::TMapPens CInterfMngr::_Pens;
58 CPen CInterfMngr::_DefaultPen;
59 CInterfMngr::TMapButtons CInterfMngr::_Buttons;
60 CButtonBase CInterfMngr::_DefaultButton;
62 CInterfMngr::TMapFuncCtrl CInterfMngr::_CtrlFunctions;
64 CInterfMngr::TMapWindows CInterfMngr::_Windows;
65 CInterfMngr::TOSD CInterfMngr::_OSD;
66 CInterfMngr::TUint CInterfMngr::_OSDWaitingDestruction;
67 CInterfMngr::TOSD CInterfMngr::_OSDWaitingInsertion;
69 CInterfMngr::TMapOSDBase CInterfMngr::_OSDLook;
70 COSDBase CInterfMngr::_DefaultOSDLook;
72 uint32 CInterfMngr::_WindowSizeX;
73 uint32 CInterfMngr::_WindowSizeY;
76 ///////////////
77 // Functions //
78 ///////////////
79 //-----------------------------------------------
80 // init :
81 // Initialize the interfaces manager.
82 //-----------------------------------------------
83 void CInterfMngr::init(const CInterfMngr::TMapFuncCtrl &funcCtrlMap, uint32 width, uint32 height)
85 _WindowSizeX = width;
86 _WindowSizeY = height;
88 loadTexts();
89 loadTextures();
90 loadPens();
91 loadCtrls();
92 loadButtons();
93 loadOSDLook();
94 setFuncCtrl(funcCtrlMap);
95 }// init //
97 //-----------------------------------------------
98 // release :
99 // Release all the interface.
100 //-----------------------------------------------
101 void CInterfMngr::release()
103 // Release OSD Look.
104 for(TMapOSDBase::iterator itOSDLook = _OSDLook.begin(); itOSDLook != _OSDLook.end(); ++itOSDLook)
106 if((*itOSDLook).second)
108 delete (*itOSDLook).second;
109 (*itOSDLook).second = 0;
114 // Delete OSDs.
115 for(TMapWindows::iterator it = _Windows.begin(); it != _Windows.end(); ++it)
117 if((*it).second)
119 delete (*it).second;
120 (*it).second = 0;
123 // Clear all Container
124 _Windows.clear();
125 _OSD.clear();
126 _OSDWaitingDestruction.clear();
127 _OSDWaitingInsertion.clear();
128 _CtrlFunctions.clear();
129 }// release //
131 //-----------------------------------------------
132 // loadCtrls :
133 // Load the array to convert a control id into a control type.
134 //-----------------------------------------------
135 void CInterfMngr::loadCtrls()
137 string interfaceFile = CPath::lookup("ctrls.txt");
138 ifstream file(interfaceFile.c_str(), ios::in);
140 // Open the file.
141 if(file.is_open())
143 char tmpBuff[_MAX_LINE_SIZE];
144 char delimiterBox[] = "[] \t";
145 uint line = 0;
147 while(!file.eof())
149 file.getline(tmpBuff, _MAX_LINE_SIZE);
150 line++;
151 char *str;
152 char *key = strtok(tmpBuff, delimiterBox);
154 // the character '/' is used to indicate comments in the controls txt file
155 if( (key != NULL) && (*key) != '/' )
157 uint id = atoi(key);
158 // If the ID != 0 -> ID Valide.
159 if(id != 0)
161 str = strtok(NULL, delimiterBox);
162 if(str != NULL)
164 if(strcmp(str, "TEXT") == 0)
165 _Ctrls.insert(TMapCtrls::value_type(id, CtrlText));
166 else if(strcmp(str, "CAPTURE") == 0)
167 _Ctrls.insert(TMapCtrls::value_type(id, CtrlCapture));
168 else if(strcmp(str, "BUTTON") == 0)
169 _Ctrls.insert(TMapCtrls::value_type(id, CtrlButton));
170 else if(strcmp(str, "RADIO_CONTROLLER") == 0)
171 _Ctrls.insert(TMapCtrls::value_type(id, CtrlRadioController));
172 else if(strcmp(str, "RADIO_BUTTON") == 0)
173 _Ctrls.insert(TMapCtrls::value_type(id, CtrlRadioButton));
174 else if(strcmp(str, "BITMAP") == 0)
175 _Ctrls.insert(TMapCtrls::value_type(id, CtrlBitmap));
176 else if(strcmp(str, "LIST") == 0)
177 _Ctrls.insert(TMapCtrls::value_type(id, CtrlList));
178 else if(strcmp(str, "MULTI_LIST") == 0)
179 _Ctrls.insert(TMapCtrls::value_type(id, CtrlMultiList));
180 else if(strcmp(str, "CHAT") == 0)
181 _Ctrls.insert(TMapCtrls::value_type(id, CtrlChat));
182 else if(strcmp(str, "CHAT_INPUT") == 0)
183 _Ctrls.insert(TMapCtrls::value_type(id, CtrlChatInput));
184 else if(strcmp(str, "CHOICE_LIST") == 0)
185 _Ctrls.insert(TMapCtrls::value_type(id, CtrlChoiceList));
186 else if(strcmp(str, "CANDIDATE_LIST") == 0)
187 _Ctrls.insert(TMapCtrls::value_type(id, CtrlCandidateList));
188 else if(strcmp(str, "HORIZONTAL_LIST") == 0)
189 _Ctrls.insert(TMapCtrls::value_type(id, CtrlHorizontalList));
190 else if(strcmp(str, "CONTROL_LIST") == 0)
191 _Ctrls.insert(TMapCtrls::value_type(id, CtrlControlList));
192 else if(strcmp(str, "SPELL_LIST") == 0)
193 _Ctrls.insert(TMapCtrls::value_type(id, CtrlSpellList));
194 else if(strcmp(str, "PROGRESS_BAR") == 0)
195 _Ctrls.insert(TMapCtrls::value_type(id, CtrlProgressBar));
196 else if(strcmp(str, "CASTING_BAR") == 0) // TEMP
197 _Ctrls.insert(TMapCtrls::value_type(id, CtrlCastingBar));
198 else if(strcmp(str, "BRICK_CONTROL") == 0)
199 _Ctrls.insert(TMapCtrls::value_type(id, CtrlBrick));
200 else
201 _Ctrls.insert(TMapCtrls::value_type(id, CtrlUnknown));
204 // ID is not Valide 0 is reserved for the OSD.
205 else
207 nlerror("\"ctrls.txt\": Line %d : 0 must not be used for a control ID !!", line);
211 file.close();
213 }// loadCtrls //
216 //-----------------------------------------------
217 // loadOSDLook :
218 // Load The look of OSDs.
219 //-----------------------------------------------
220 void CInterfMngr::loadOSDLook()
222 string interfaceFile = CPath::lookup("OSDs.txt");
223 ifstream file(interfaceFile.c_str(), ios::in);
225 // Open the file.
226 if(file.is_open())
228 char tmpBuff[_MAX_LINE_SIZE];
229 char delimiter[] = "[] \t";
230 char *ptr = 0;
232 bool defaultCase = false;
233 uint id;
235 COSD::TBG bgMode = COSD::BG_none;
236 uint bg = 0;
237 CRGBA bgColor;
239 COSD::TTB tbMode = COSD::TB_none;
240 uint tb = 0;
241 CRGBA tbColor;
242 uint tbPen = 0;
244 uint hlSize = 1;
245 CRGBA hlColor;
247 uint rsSize = 4;
248 CRGBA rsColor;
251 // While the end of the file is not reached.
252 while(!file.eof())
254 // Get a line (the line should not be more than _MAX_LINE_SIZE).
255 file.getline(tmpBuff, _MAX_LINE_SIZE);
257 // Get the Id
258 ptr = strtok(tmpBuff, delimiter);
259 // If empty line -> next line.
260 if(ptr == NULL)
261 continue;
263 // If the id == "..." -> default case.
264 if(strcmp(ptr, "...") == 0)
266 defaultCase = true;
268 else
270 // Make the id.
271 id = atoi(ptr);
272 defaultCase = false;
275 // Get the first token delimited by the characters in delimiter.
276 ptr = strtok(NULL, delimiter);
277 while(ptr != NULL)
279 // Get the Background Mode.
280 if(strcmp(ptr, "BG_Mode:") == 0)
281 bgMode = getBGMode();
282 // Get BG Bitmap.
283 else if(strcmp(ptr, "BG_Bitmap:") == 0)
284 bg = getInt();
285 // Get BG Color.
286 else if(strcmp(ptr, "BG_Color:") == 0)
287 bgColor = getRGBA();
289 // Get the Title Bar Mode.
290 else if(strcmp(ptr, "TB_Mode:") == 0)
291 tbMode = getTBMode();
292 // Get TB Bitmap.
293 else if(strcmp(ptr, "TB_Bitmap:") == 0)
294 tb = getInt();
295 // Get TB Color.
296 else if(strcmp(ptr, "TB_Color:") == 0)
297 tbColor = getRGBA();
298 // Get TB Pen.
299 else if(strcmp(ptr, "TB_Pen:") == 0)
300 tbPen = getInt();
302 // Get HL Size.
303 else if(strcmp(ptr, "HL_Pen:") == 0)
304 hlSize = getInt();
305 // Get HL Color.
306 else if(strcmp(ptr, "HL_Color:") == 0)
307 hlColor = getRGBA();
309 // Get RS Size.
310 else if(strcmp(ptr, "RS_Pen:") == 0)
311 rsSize = getInt();
312 // Get RS Color.
313 else if(strcmp(ptr, "RS_Color:") == 0)
314 rsColor = getRGBA();
316 // Next Token.
317 ptr = strtok(NULL, delimiter);
321 // Set the Default Pen.
322 if(defaultCase)
324 _DefaultOSDLook._BG_Mode = bgMode;
325 _DefaultOSDLook._BG = bg;
326 _DefaultOSDLook._BG_Color = bgColor;
328 _DefaultOSDLook._TB_Mode = tbMode;
329 _DefaultOSDLook._TB = tb;
330 _DefaultOSDLook._TB_Color = tbColor;
331 _DefaultOSDLook._TB_Pen = getPen(tbPen);
333 _DefaultOSDLook._HL_Size = (float)hlSize;
334 _DefaultOSDLook._HL_Color = hlColor;
336 _DefaultOSDLook._RS_Size = (float)rsSize;
337 _DefaultOSDLook._RS_Color = rsColor;
339 // Set specific Pens.
340 else
342 COSDBase *osdBase = new COSDBase;
343 osdBase->_BG_Mode = bgMode;
344 osdBase->_BG = bg;
345 osdBase->_BG_Color = bgColor;
347 osdBase->_TB_Mode = tbMode;
348 osdBase->_TB = tb;
349 osdBase->_TB_Color = tbColor;
350 osdBase->_TB_Pen = getPen(tbPen);
352 osdBase->_HL_Size = (float)hlSize;
353 osdBase->_HL_Color = hlColor;
355 osdBase->_RS_Size = (float)rsSize;
356 osdBase->_RS_Color = rsColor;
358 // Insert the text.
359 _OSDLook.insert(TMapOSDBase::value_type(id, osdBase));
362 // Close the file.
363 file.close();
365 }// loadOSDLook //
368 //-----------------------------------------------
369 // loadTexts :
370 // Load all texts.
371 //-----------------------------------------------
372 void CInterfMngr::loadTexts()
374 string interfaceFile = CPath::lookup("texts.txt");
375 ifstream file(interfaceFile.c_str(), ios::in);
377 // Open the file.
378 if(file.is_open())
380 char tmpBuff[_MAX_LINE_SIZE];
381 char delimiterBox[] = "[]";
383 while(!file.eof())
385 file.getline(tmpBuff, _MAX_LINE_SIZE);
386 char *str;
387 char *key = strtok( tmpBuff, delimiterBox);
388 if(key != NULL)
390 uint id = atoi(key);
391 str = strtok( NULL, delimiterBox);
392 if(str != NULL)
393 _Texts.insert(TMapTexts::value_type(id, ucstring(str)));
396 file.close();
398 }// loadTexts //
400 //-----------------------------------------------
401 // Load Textures
402 // Load all textures needed for the interfaces.
403 //-----------------------------------------------
404 void CInterfMngr::loadTextures()
406 /* string interfaceFile = CPath::lookup("textures.txt");
407 ifstream file(interfaceFile.c_str(), ios::in);
409 // Open the file.
410 if(file.is_open())
412 char tmpBuff[_MAX_LINE_SIZE];
413 char delimiterBox[] = "[]";
415 while(!file.eof())
417 file.getline(tmpBuff, _MAX_LINE_SIZE);
418 char *str;
419 char *key = strtok( tmpBuff, delimiterBox);
420 if(key != NULL)
422 uint id = atoi(key);
423 str = strtok( NULL, delimiterBox);
424 if(str != NULL)
426 _Textures.insert(TMapTextures::value_type(id, Driver->createTextureFile(string(str))));
430 file.close();
432 }// loadTextures //
436 //-----------------------------------------------
437 // loadPens :
438 // Load Pens from file.
439 //-----------------------------------------------
440 void CInterfMngr::loadPens()
442 string interfaceFile = CPath::lookup("pens.txt");
443 ifstream file(interfaceFile.c_str(), ios::in);
445 // Try to open the file.
446 if(file.is_open())
448 char tmpBuff[_MAX_LINE_SIZE];
449 char delimiterBox[] = "[] \t";
451 // While the end of the file is not reached.
452 while(!file.eof())
454 // Get a line (teh line should not be more than _MAX_LINE_SIZE).
455 file.getline(tmpBuff, _MAX_LINE_SIZE);
456 // Get the first token delimited by the characters in delimiterBox.
457 char *token = strtok(tmpBuff, delimiterBox);
458 if(token != NULL)
460 uint32 fontSize = 20;
461 uint8 r = 255;
462 uint8 g = 255;
463 uint8 b = 255;
464 uint8 a = 255;
465 bool shadow = false;
466 sint tmp = 0;
467 bool defaultCase = false;
468 uint id;
470 // If the id == "..." -> default case.
471 if(strcmp(token, "...") == 0)
473 defaultCase = true;
475 else
477 // Make the id.
478 id = atoi(token);
479 defaultCase = false;
482 // Get the font size.
483 token = strtok(NULL, delimiterBox);
484 if(token != NULL)
485 fontSize = atoi(token);
487 // Get the text color
488 token = strtok(NULL, delimiterBox);
489 if(token != NULL)
490 r = atoi(token);
491 token = strtok(NULL, delimiterBox);
492 if(token != NULL)
493 g = atoi(token);
494 token = strtok(NULL, delimiterBox);
495 if(token != NULL)
496 b = atoi(token);
497 token = strtok(NULL, delimiterBox);
498 if(token != NULL)
499 a = atoi(token);
501 // Get the shadow.
502 token = strtok(NULL, delimiterBox);
503 if(token != NULL)
505 tmp = atoi(token);
506 if(tmp)
507 shadow = true;
508 else
509 shadow = false;
512 // Set the Default Pen.
513 if(defaultCase)
515 _DefaultPen.color(CRGBA(r,g,b,a));
516 _DefaultPen.fontSize(fontSize);
517 _DefaultPen.shadow(shadow);
519 // Set specific Pens.
520 else
522 // Insert the text.
523 _Pens.insert(TMapPens::value_type(id, new CPen(fontSize, CRGBA(r,g,b,a), shadow)));
527 file.close();
529 }// loadPens //
532 //-----------------------------------------------
533 // loadButtons :
534 // Load Buttons from file.
535 //-----------------------------------------------
536 void CInterfMngr::loadButtons()
538 string interfaceFile = CPath::lookup("buttons.txt");
539 ifstream file(interfaceFile.c_str(), ios::in);
541 // Try to open the file.
542 if(file.is_open())
544 char tmpBuff[_MAX_LINE_SIZE];
545 char delimiter[] = "[] \t";
547 // While the end of the file is not reached.
548 while(!file.eof())
550 // Get a line (teh line should not be more than _MAX_LINE_SIZE).
551 file.getline(tmpBuff, _MAX_LINE_SIZE);
552 // Get the first token delimited by the characters in delimiter.
553 char *token = strtok(tmpBuff, delimiter);
554 if(token != NULL)
556 CRGBA rgbaOn;
557 CRGBA rgbaOff;
558 CRGBA rgbaDisable;
560 bool defaultCase = false;
561 uint id;
562 uint tON = 0;
563 uint tOFF = 0;
564 uint tDIS = 0;
566 CButtonBase::TBG bgOn = CButtonBase::BG_stretch;
567 CButtonBase::TBG bgOff = CButtonBase::BG_stretch;
568 CButtonBase::TBG bgDisable = CButtonBase::BG_stretch;
571 // If the id == "..." -> default case.
572 if(strcmp(token, "...") == 0)
574 defaultCase = true;
576 else
578 // Make the id.
579 id = atoi(token);
580 defaultCase = false;
583 char *ptr = strtok(NULL, delimiter);
584 while(ptr != NULL)
586 if (strcmp(ptr, "BG_Mode_On:") == 0)
587 bgOn = getBGMode2();
588 else if(strcmp(ptr, "BG_Mode_Off:") == 0)
589 bgOff = getBGMode2();
590 else if(strcmp(ptr, "BG_Mode_Dis:") == 0)
591 bgDisable = getBGMode2();
593 else if(strcmp(ptr, "t_On:") == 0)
594 tON = getInt();
595 else if(strcmp(ptr, "t_Off:") == 0)
596 tOFF = getInt();
597 else if(strcmp(ptr, "t_Dis:") == 0)
598 tDIS = getInt();
600 else if(strcmp(ptr, "RGBA_On:") == 0)
601 rgbaOn = getRGBA();
602 else if(strcmp(ptr, "RGBA_Off:") == 0)
603 rgbaOff = getRGBA();
604 else if(strcmp(ptr, "RGBA_Dis:") == 0)
605 rgbaDisable = getRGBA();
607 // Next token
608 ptr = strtok(NULL, delimiter);
611 // Set the Default Pen.
612 if(defaultCase)
614 _DefaultButton.colorOn(rgbaOn);
615 _DefaultButton.colorOff(rgbaOff);
616 _DefaultButton.colorDisable(rgbaDisable);
617 _DefaultButton.textureOn(tON);
618 _DefaultButton.textureOff(tOFF);
619 _DefaultButton.textureDisable(tDIS);
620 _DefaultButton.bgModeOn(bgOn);
621 _DefaultButton.bgModeOff(bgOff);
622 _DefaultButton.bgModeDisable(bgDisable);
624 // Set specific Pens.
625 else
627 // Insert the button.
628 CButtonBase *button = new CButtonBase(tON, tOFF, tDIS, rgbaOn, rgbaOff, rgbaDisable);
629 if(button)
631 button->bgModeOn(bgOn);
632 button->bgModeOff(bgOff);
633 button->bgModeDisable(bgDisable);
635 _Buttons.insert(TMapButtons::value_type(id, button));
639 file.close();
641 }// loadButtons //
643 //-----------------------------------------------
644 // setFuncCtrl :
645 // Pointer on an array of TFuncCtrl.
646 //-----------------------------------------------
647 void CInterfMngr::setFuncCtrl(const TMapFuncCtrl &funcCtrlMap)
649 _CtrlFunctions = funcCtrlMap;
650 }// setFuncCtrl //
655 //-----------------------------------------------
656 // getType :
657 // Get the type of the control.
658 //-----------------------------------------------
659 CInterfMngr::TTypCtrl CInterfMngr::getType(uint id)
661 TMapCtrls::iterator it = _Ctrls.find(id);
662 if(it != _Ctrls.end())
663 return (*it).second;
664 else
665 return CtrlUnknown;
666 }// getType //
668 //-----------------------------------------------
669 // getText :
670 // Return the text corresponding to the Id.
671 //-----------------------------------------------
672 ucstring CInterfMngr::getText(uint id)
674 TMapTexts::iterator it = _Texts.find(id);
675 if(it != _Texts.end())
676 return (*it).second;
677 else
678 return ucstring("");
679 }// getText //
681 //-----------------------------------------------
682 // getTexture :
683 // Return the texture file Corresponding to the id.
684 //-----------------------------------------------
685 UTextureFile * CInterfMngr::getTexture(uint id)
687 TMapTextures::iterator it = _Textures.find(id);
688 if(it != _Textures.end())
689 return (*it).second;
690 else
691 return 0;
692 }// getTexture //
694 //-----------------------------------------------
695 // getPen :
696 // Get the right Pen for the control.
697 //-----------------------------------------------
698 CPen CInterfMngr::getPen(uint id)
700 TMapPens::iterator it = _Pens.find(id);
701 if(it != _Pens.end())
702 return *((*it).second);
703 else
704 return _DefaultPen;
705 }// getPen //
707 //-----------------------------------------------
708 // getButton :
709 // Get the right Button for the control.
710 //-----------------------------------------------
711 CButtonBase CInterfMngr::getButton(uint id)
713 TMapButtons::iterator it = _Buttons.find(id);
714 if(it != _Buttons.end())
715 return *((*it).second);
716 else
717 return _DefaultButton;
718 }// getButton //
720 //-----------------------------------------------
721 // getCtrl :
722 // ...
723 //-----------------------------------------------
724 CControl * CInterfMngr::getCtrl(uint idCtrl)
726 CControl *ctrl = 0;
727 TMapWindows::iterator itE = _Windows.end();
728 for(TMapWindows::iterator it = _Windows.begin(); it != itE ; ++it)
730 ctrl = ((*it).second)->getCtrl(idCtrl);
731 if(ctrl)
732 break;
735 // Return the pointer of the control "id" or 0 if the control "id" doesn't exit.
736 return ctrl;
737 }// getCtrl //
740 //-----------------------------------------------
741 // getOSDLook :
742 // Get the OSD Look.
743 //-----------------------------------------------
744 COSDBase CInterfMngr::getOSDLook(uint id)
746 TMapOSDBase::iterator it = _OSDLook.find(id);
747 if(it != _OSDLook.end())
748 return *((*it).second);
749 else
750 return _DefaultOSDLook;
751 }// getOSDLook //
756 //-----------------------------------------------
757 // createOSD
758 // Create the OSD "id".
759 //-----------------------------------------------
760 COSD* CInterfMngr::createOSD(uint id, bool popUp)
762 COSD *win = NULL;
764 char filename[20];
765 sprintf(filename,"%d.txt", id);
766 string interfaceFile = CPath::lookup(filename);
767 ifstream file(interfaceFile.c_str(), ios::in);
769 // Open the file.
770 if(file.is_open())
772 char tmpBuff[_MAX_LINE_SIZE];
773 char delimiter[] = "[] \t";
775 float x = 0.f;
776 float y = 0.f;
777 float width = 1.f;
778 float height = 1.f;
779 float minWidth = 0.f;
780 float minHeight = 0.f;
781 uint func = 0;
782 uint name = 0;
783 COSD::TBG bgMode = COSD::BG_none;
785 file.getline(tmpBuff, _MAX_LINE_SIZE);
787 char *ptr = strtok(tmpBuff, delimiter);
788 while(ptr != NULL)
790 // Get the pos X of the OSD.
791 if(strcmp(ptr, "X:") == 0)
792 x = getFloat();
793 // Get the pos Y of the OSD.
794 else if(strcmp(ptr, "Y:") == 0)
795 y = getFloat();
796 // Get the Width of the OSD.
797 else if(strcmp(ptr, "Width:") == 0)
798 width = getFloat();
799 // Get the Height of the OSD.
800 else if(strcmp(ptr, "Height:") == 0)
801 height = getFloat();
802 // Get the MinWidth of the OSD.
803 else if(strcmp(ptr, "MinWidth:") == 0)
804 minWidth = getFloat();
805 // Get the MinHeight of the OSD.
806 else if(strcmp(ptr, "MinHeight:") == 0)
807 minHeight = getFloat();
808 // Get the function to call each frame.
809 else if(strcmp(ptr, "Function:") == 0)
810 func = getInt();
811 // Get the function to call each frame.
812 else if(strcmp(ptr, "Name:") == 0)
813 name = getInt();
814 // Get Background Mode.
815 else if(strcmp(ptr, "BG_Mode:") == 0)
816 bgMode = getBGMode();
818 // Next Token
819 ptr = strtok(NULL, delimiter);
822 // Create the window.
823 win = new COSD(id, x, y, 0.f, 0.f, 0.f, 0.f, width, height, minWidth, minHeight, popUp);
824 if(win != 0)
826 COSDBase osdLook = getOSDLook(id);
828 // Set the Background display mode.
829 win->bgMode(osdLook._BG_Mode);
830 // Set the BG Texture.
831 win->bg(osdLook._BG);
832 // Set the BG Color
833 win->bgColor(osdLook._BG_Color);
835 // Set the Title Bar display mode.
836 win->tbMode(osdLook._TB_Mode);
837 // Set the TB Texture.
838 win->tb(osdLook._TB);
839 // Set the TB Color.
840 win->tbColor(osdLook._TB_Color);
841 // Set the TB Pen.
842 win->tbPen(osdLook._TB_Pen);
844 // Set the HighLight Size.
845 win->hlSize(osdLook._HL_Size);
846 // Set the HL Color.
847 win->hlColor(osdLook._HL_Color);
849 // Set the Resize Size.
850 win->rsSize(osdLook._RS_Size);
851 // Set the RS Color.
852 win->rsColor(osdLook._RS_Color);
854 // win->osdMode(COSD::locked);
855 // Change the OSD Name.
856 win->osdName(getText(name));
858 // Add the OSD to the OSD that are waiting insertion
859 _Windows.insert( TMapWindows::value_type( id, win) );
860 _OSDWaitingInsertion.push_back( win );
862 // Open the OSD.
863 win->open(file);
865 // win->osdSetPosition(0.f, 0.f);
866 // win->osdSetSize(1.f,1.f);
869 // Close the File.
870 file.close();
873 return win;
874 }// createOSD //
876 //-----------------------------------------------
877 // deleteOSD :
878 // Delete the OSD "id".
879 //-----------------------------------------------
880 void CInterfMngr::deleteOSD(uint id)
882 // store it the list of OSD waiting destruction
883 _OSDWaitingDestruction.push_back(id);
884 }// deleteOSD //
888 //-----------------------------------------------
889 // resize :
890 // The window size has changed -> resize interface.
891 //-----------------------------------------------
892 void CInterfMngr::resize(uint32 width, uint32 height)
894 _WindowSizeX = width;
895 _WindowSizeY = height;
897 // If the window is too small -> return;
898 if(_WindowSizeX==0 || _WindowSizeY==0)
899 return;
901 // Update the interface.
902 for(TOSD::iterator it = _OSD.begin(); it != _OSD.end(); it++)
904 // Resize all controls.
905 (*it)->resize(width, height);
907 }// resize //
910 //-----------------------------------------------
911 // update :
912 // Update Interfaces (for timer, etc.).
913 //-----------------------------------------------
914 void CInterfMngr::update(float x, float y)
916 bool fullUse = true;
918 // delete all the OSD waiting destruction
919 TUint::iterator itEID = _OSDWaitingDestruction.end();
920 TMapWindows::iterator itW;
922 for (TUint::iterator itID = _OSDWaitingDestruction.begin() ; itID != itEID ; ++itID)
925 itW = _Windows.find(*itID);
926 if(itW != _Windows.end())
928 // Get the pointer.
929 COSD *OSD = (*itW).second;
931 // erase the OSD.
932 _Windows.erase(itW);
934 // Find the OSD in the display list.
935 for(TOSD::iterator itOSD = _OSD.begin(); itOSD != _OSD.end(); itOSD++)
937 // if it's the right OSD -> erase.
938 if((*itOSD) == OSD)
940 _OSD.erase(itOSD);
941 break;
945 // delete the OSD.
946 if(OSD)
948 delete OSD;
949 OSD = 0;
954 _OSDWaitingDestruction.clear();
957 // insert all OSD newly created
958 const TOSD::const_iterator itNewEnd = _OSDWaitingInsertion.end();
960 for (TOSD::const_iterator itNew = _OSDWaitingInsertion.begin() ; itNew != itNewEnd ; ++itNew)
962 _OSD.push_front((*itNew));
965 _OSDWaitingInsertion.clear();
967 // Update the interface.
968 // const TOSD::iterator itE = _OSD.end();
969 for(TOSD::iterator it = _OSD.begin(); it != _OSD.end() ; ++it)
971 if((*it)->update(x, y, fullUse))
972 fullUse = false;
974 }// update //
976 //-----------------------------------------------
977 // display :
978 // Display the interfaces in progress.
979 //-----------------------------------------------
980 void CInterfMngr::display()
982 // If the window is too small -> return;
983 if(_WindowSizeX==0 || _WindowSizeY==0)
984 return;
986 const TOSD::reverse_iterator itRE = _OSD.rend();
987 for(TOSD::reverse_iterator it = _OSD.rbegin(); it != itRE ; ++it)
989 (*it)->display();
991 }// display //
993 //-----------------------------------------------
994 // cursor :
995 // Return the cursor used by the interface at the moment.
996 // \return ECursor : 'Cur_None' if no cursor needed for the interface.
997 // \warning This method should be called after the update one to be up to date.
998 //-----------------------------------------------
999 COSD::ECursor CInterfMngr::cursor()
1001 // If the window is too small -> return;
1002 if(_WindowSizeX==0 || _WindowSizeY==0)
1003 return COSD::Cur_None;
1005 for(TOSD::iterator it = _OSD.begin(); it != _OSD.end() ; ++it)
1007 COSD::ECursor curs = (*it)->cursor();
1008 if(curs != COSD::Cur_None)
1009 return curs;
1012 return COSD::Cur_None;
1013 }// cursor //
1015 //-----------------------------------------------
1016 // click :
1017 // Manage the mouse click.
1018 //-----------------------------------------------
1019 bool CInterfMngr::click(float x, float y)
1021 // If the window is too small -> return;
1022 if(_WindowSizeX==0 || _WindowSizeY==0)
1023 return false;
1025 bool taken = false;
1026 bool focus = false;
1028 const TOSD::iterator itE = _OSD.end();
1029 TOSD::iterator itFrontOSD = itE;
1031 for(TOSD::iterator it = _OSD.begin(); it != itE ; ++it)
1033 (*it)->click(x, y, taken);
1034 if( taken && (!focus) )
1036 itFrontOSD = it;
1037 focus = true;
1041 if (itFrontOSD != itE)
1043 _OSD.push_front(*itFrontOSD);
1044 _OSD.erase(itFrontOSD);
1047 // Return if the click is taken by the interface.
1048 return taken;
1049 }// click //
1053 //-----------------------------------------------
1054 // clickRight :
1055 // Manage the mouse right click.
1056 //-----------------------------------------------
1057 bool CInterfMngr::clickRight(float x, float y)
1059 // If the window is too small -> return;
1060 if(_WindowSizeX==0 || _WindowSizeY==0)
1061 return false;
1063 bool taken = false;
1064 bool focus = false;
1066 const TOSD::iterator itE = _OSD.end();
1067 TOSD::iterator itFrontOSD = itE;
1069 for(TOSD::iterator it = _OSD.begin(); it != itE ; ++it)
1071 (*it)->clickRight(x, y, taken);
1072 if( taken && (!focus) )
1074 itFrontOSD = it;
1075 focus = true;
1079 if (itFrontOSD != itE)
1081 _OSD.push_front(*itFrontOSD);
1082 _OSD.erase(itFrontOSD);
1085 // Return if the click is taken by the interface.
1086 return taken;
1087 }// clickRight //
1090 //-----------------------------------------------
1091 // getOSD :
1092 // get the specified OSD adress
1093 //-----------------------------------------------
1094 COSD* CInterfMngr::getOSD( uint id)
1096 TMapWindows::const_iterator it, itE = _Windows.end();
1098 it = _Windows.find( id );
1100 if (it != itE)
1101 return (*it).second;
1102 else
1103 return NULL;
1105 }// getOSD //