Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / client / src / interfaces_manager / osd.cpp
blob53638e355c985fe7408860aab034694b37240abf
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 "osd.h"
31 #include "text.h"
32 #include "capture.h"
33 #include "button.h"
34 #include "radio_button.h"
35 #include "radio_controller.h"
36 #include "bitmap.h"
37 #include "interfaces_manager.h"
38 #include "interf_list.h"
39 #include "multi_list.h"
40 #include "interf_script.h"
41 #include "chat_control.h"
42 #include "chat_input.h"
43 #include "choice_list.h"
44 #include "candidate_list.h"
45 #include "horizontal_list.h"
46 #include "control_list.h"
47 #include "spell_list.h"
48 #include "progress_bar.h"
49 #include "casting_bar.h"
50 #include "brick_control.h"
51 // Std
52 #include <string>
55 ///////////
56 // Using //
57 ///////////
58 using namespace NLMISC;
59 using namespace NL3D;
60 using namespace std;
63 /////////////
64 // Externs //
65 /////////////
66 extern UDriver *Driver;
67 extern UTextContext *TextContext;
70 static std::list< uint16 > elts;
73 ///////////
74 // MACRO //
75 ///////////
76 // Macro pour toute la partie commune de lecture des scripts pour les controls.
77 #define CONTROL_SCRIPT_MACRO(UserScript) \
79 CControl::THotSpot hs = CControl::HS_MM; \
80 CControl::THotSpot origin = CControl::HS_MM;\
81 uint idParent = 0; \
82 float x = 0.f; \
83 float y = 0.f; \
84 float xPixel = 0.f; \
85 float yPixel = 0.f; \
86 float w = 0.f; \
87 float h = 0.f; \
88 float wPixel = 0.f; \
89 float hPixel = 0.f; \
91 elts.clear(); \
92 char delimiter[] = "[] \t"; \
93 char *ptr = strtok(NULL, delimiter); \
94 while(ptr != NULL) \
95 { \
96 if(strcmp(ptr, "HotSpot:") == 0) \
97 hs = getHotSpot(); \
98 else if(strcmp(ptr, "Origin:") == 0) \
99 origin = getHotSpot(); \
100 else if(strcmp(ptr, "Parent:") == 0) \
101 idParent = getInt(); \
102 else if(strcmp(ptr, "X:") == 0) \
103 x = getFloat(); \
104 else if(strcmp(ptr, "Y:") == 0) \
105 y = getFloat(); \
106 else if(strcmp(ptr, "X_Pixel:") == 0) \
107 xPixel = getFloat(); \
108 else if(strcmp(ptr, "Y_Pixel:") == 0) \
109 yPixel = getFloat(); \
110 else if(strcmp(ptr, "W:") == 0) \
111 w = getFloat(); \
112 else if(strcmp(ptr, "H:") == 0) \
113 h = getFloat(); \
114 else if(strcmp(ptr, "W_Pixel:") == 0) \
115 wPixel = getFloat(); \
116 else if(strcmp(ptr, "H_Pixel:") == 0) \
117 hPixel = getFloat(); \
119 UserScript \
121 ptr = strtok(NULL, delimiter); \
127 //-----------------------------------------------
128 // COSD :
129 // Constructor.
130 //-----------------------------------------------
131 COSD::COSD(bool popUp)
133 // Common init for all constructors.
134 init(0, 0.f, 0.f, 0.f, 0.f, 1.f, 1.f, 0.f, 0.f, 0.0f, 0.0f, popUp);
135 }// COSD //
137 //-----------------------------------------------
138 // COSD :
139 // Constructor.
140 //-----------------------------------------------
141 COSD::COSD(uint id, float x, float y, float x_pixel, float y_pixel, float w, float h, float w_pixel, float h_pixel, float minWidth, float minHeight, bool popUp)
143 // Common init for all constructors.
144 init(id, x, y, x_pixel, y_pixel, w, h, w_pixel, h_pixel, minWidth, minHeight, popUp);
145 }// COSD //
148 //-----------------------------------------------
149 // init :
150 // Initialize the OSD (1 function called for all constructors -> easier).
151 //-----------------------------------------------
152 void COSD::init(uint id, float x, float y, float x_pixel, float y_pixel, float w, float h, float w_pixel, float h_pixel, float minWidth, float minHeight, bool popUp)
154 _Id = id;
155 _PopUp = popUp;
157 // pop up are never resizable
158 if (_PopUp == true)
159 _OSD_Mode = TMode::locked;
161 // Default is OSD visible.
162 _Show = true;
164 _W_Min = minWidth; // minimal width of the OSD
165 _H_Min = minHeight; // minimal height of the OSD
167 _X = x; // Position X of the OSD (between 0-1).
168 _Y = y; // Position Y of the OSD (between 0-1).
169 _X_Pixel = x_pixel; // Position X of the OSD (in Pixel).
170 _Y_Pixel = y_pixel; // Position Y of the OSD (in Pixel).
172 _W = w; // Width of the OSD (between 0-1).
173 _H = h; // Height of the OSD (between 0-1).
174 _W_Pixel = w_pixel; // Width of the OSD (in Pixel).
175 _H_Pixel = h_pixel; // Height of the OSD (in Pixel).
177 // How to display the OSD.
178 _OSD_Mode = none;
179 // Name of the OSD;
180 _OSD_Name = ucstring("");
182 // NO Background
183 _BG_Mode = BG_none;
185 // NO Title Bar
186 _TB_Mode = TB_none;
187 // Height of the move zone.
188 _TB_H = 20;
189 // Pen for the OSD Name.
190 _TB_Pen = CPen(15, CRGBA(255,0,150,255), true);
192 // HighLight size in pixel.
193 _HL_Size = 1;
195 // Resize
196 _RS_Mode = no_resize;
197 // Color of the Move zone.
198 _RS_Color = CRGBA(200,200,200,128);
199 // Width of the resize zone.
200 _RS_Size = 4;
202 // NO update Function.
203 _OSD_Update_Func = 0;
205 // Calculate others variables.
206 // calculateDisplay(); // done into the 'resize' method, called by the 'open' method
208 }// init //
210 //-----------------------------------------------
211 // ~COSD :
212 // Destructor.
213 //-----------------------------------------------
214 COSD::~COSD()
216 // Get all the controls and destroy them.
217 for(TMapControls::iterator it = _Controls.begin(); it != _Controls.end(); it++)
219 // Delete the control if still allocated.
220 if((*it).second != NULL)
222 delete ((*it).second);
223 (*it).second = 0;
227 // Clear all the control.
228 _Controls.clear();
229 _Children.clear();
230 }// ~COSD //
233 //-----------------------------------------------
234 // display :
235 // Display the OSD.
236 //-----------------------------------------------
237 void COSD::display()
239 // Is the OSD is not visible -> return;
240 if(!_Show)
241 return;
243 // Draw the background
244 drawBG();
246 // Backup scissor and change scissor to clip the list correctly.
247 CScissor oldScissor = Driver->getScissor();
248 CScissor scissor;
249 scissor.init(_X_Display, _Y_Display, _W_Display, _H_Display);
250 Driver->setScissor(scissor);
252 // Draw controls in the OSD.
253 for(TListControl::reverse_iterator it = _Children.rbegin(); it != _Children.rend(); it++)
254 (*it)->display();
256 // Restore Scissor.
257 Driver->setScissor(oldScissor);
259 // How to display the OSD.
260 switch(_OSD_Mode)
262 // OSD HighLighted
263 case selected:
264 // Draw Borders.
265 drawBorders(_HL_W, _HL_H, _X_Display, _Y_Display, _X_Display+_W_Display, _Y_Display+_H_Display, _HL_Color);
266 break;
268 // OSD with a Border to resize.
269 case resizable:
270 // Draw big Borders.
271 drawBorders(_RS_W, _RS_H, _X_Display, _Y_Display, _X_Display+_W_Display, _Y_Display+_H_Display, _RS_Color);
272 break;
274 // OSD with a Border and an Area to move the OSD.
275 case movable:
276 // Draw the Title Bar.
277 drawTB();
279 // Draw Big Borders.
280 drawBorders(_RS_W, _RS_H, _X_Display, _Y_Display, _X_Display+_W_Display, _Y_Display+_H_Display, _RS_Color);
281 // Draw the OSD Name -> if the text is not empty.
282 if(!_OSD_Name.empty())
283 drawText(_X_Display+_W_Display/2, _Y_Display+_H_Display-_RS_H-_TB_H_Display/2, _OSD_Name, _TB_Pen);
284 break;
286 }// display //
289 //-----------------------------------------------
290 // drawBG :
291 // Function to draw the background according to the mode.
292 //-----------------------------------------------
293 void COSD::drawBG()
295 // Display the Background.
296 switch(_BG_Mode)
298 // Backgroung is only made by 1 color (RGBA).
299 case BG_plain:
300 Driver->drawQuad(_X_Display, _Y_Display, _X_Display+_W_Display, _Y_Display+_H_Display, _BG_Color);
301 break;
303 // Background is stretch at the OSD size.
304 case BG_stretch:
305 Driver->drawBitmap(_X_Display, _Y_Display, _W_Display, _H_Display, *CInterfMngr::getTexture(_BG), true, _BG_Color);
306 break;
308 // No Background.
309 default:
310 break;
312 }// drawBG //
314 //-----------------------------------------------
315 // drawTB :
316 // Function to draw the Title Bar according to the mode.
317 //-----------------------------------------------
318 void COSD::drawTB()
320 // Display Title Bar.
321 switch(_TB_Mode)
323 // Backgroung is only made by 1 color (RGBA).
324 case TB_plain:
325 Driver->drawQuad(_X_Display+_RS_W, _Y_Display+_H_Display-_RS_H-_TB_H_Display, _X_Display+_W_Display-_RS_W, _Y_Display+_H_Display-_RS_H, _TB_Color);
326 break;
328 // Background is stretch at the OSD size.
329 case TB_stretch:
330 Driver->drawBitmap(_X_Display+_RS_W, _Y_Display+_H_Display-_RS_H-_TB_H_Display, _W_Display-2*_RS_W, _TB_H_Display, *CInterfMngr::getTexture(_TB), true, _TB_Color);
331 break;
333 // No Background.
334 default:
335 break;
337 }// drawTB //
340 //-----------------------------------------------
341 // drawBorders :
342 // Draw the resize borders.
343 //-----------------------------------------------
344 void COSD::drawBorders(float bSizeW, float bSizeH, float x0, float y0, float x1, float y1, const CRGBA &color)
346 Driver->drawQuad(x0, y0, x0+bSizeW, y1, color);
347 Driver->drawQuad(x1-bSizeW, y0, x1, y1, color);
348 Driver->drawQuad(x0, y0, x1, y0+bSizeH, color);
349 Driver->drawQuad(x0, y1-bSizeH, x1, y1, color);
350 }// drawBorders //
352 //-----------------------------------------------
353 // drawText :
354 // Draw a text with all information needed.
355 //-----------------------------------------------
356 void COSD::drawText(float x, float y, const ucstring &text, const CPen &pen)
358 TextContext->setHotSpot(UTextContext::MiddleMiddle);
359 TextContext->setColor(pen.color());
360 TextContext->setFontSize(pen.fontSize());
361 TextContext->setShaded(pen.shadow());
362 TextContext->printAt(x, y, text);
363 }// drawText //
366 //-----------------------------------------------
367 // resize :
368 // The OSD size has changed -> resize controls.
369 //-----------------------------------------------
370 void COSD::resize(uint32 width, uint32 height)
372 // Update variables because of the resize.
373 calculateDisplay();
375 // resize the other controls.
376 for(TMapControls::iterator it = _Controls.begin(); it != _Controls.end(); it++)
378 // If the control as a reference different than the OSD -> the Reference will resize this control.
379 if((*it).second->parent() == 0)
381 float x, y;
382 (*it).second->resize(width, height);
383 calculatePos(x, y, (*it).second->origin());
384 (*it).second->ref(x, y, _W_Display, _H_Display);
387 }// resize //
389 //-----------------------------------------------
390 // update :
391 // Update the OSD (for timer, etc.).
392 //-----------------------------------------------
393 bool COSD::update(float x, float y, bool fullUse)
395 bool used = false;
398 // Function called every frame.
399 CInterfMngr::runFuncCtrl(_OSD_Update_Func, 0);
402 if(fullUse)
404 if(_RS_Mode != no_resize)
406 // Get the window size.
407 uint32 w, h;
408 CInterfMngr::getWindowSize(w, h);
410 // Resize correctly the OSD.
411 switch(_RS_Mode)
413 // Resize Bottom OSD Border.
414 case resize_B:
415 resizeB(x, y);
416 // Resize -> resize cursor.
417 _Cursor = Cur_Resize_B;
418 break;
419 // Resize Top OSD Border.
420 case resize_T:
421 resizeT(x, y);
422 // Resize -> resize cursor.
423 _Cursor = Cur_Resize_T;
424 break;
425 // Resize Left OSD Border.
426 case resize_L:
427 resizeL(x, y);
428 // Resize -> resize cursor.
429 _Cursor = Cur_Resize_L;
430 break;
431 // Resize Right OSD Border.
432 case resize_R:
433 resizeR(x, y);
434 // Resize -> resize cursor.
435 _Cursor = Cur_Resize_R;
436 break;
437 // Resize Bottom Left OSD Border.
438 case resize_BL:
439 resizeB(x, y);
440 resizeL(x, y);
441 // Resize -> resize cursor.
442 _Cursor = Cur_Resize_BL;
443 break;
444 // Resize Top Left OSD Border.
445 case resize_TL:
446 resizeT(x, y);
447 resizeL(x, y);
448 // Resize -> resize cursor.
449 _Cursor = Cur_Resize_TL;
450 break;
451 // Resize Bottom Right OSD Border.
452 case resize_BR:
453 resizeB(x, y);
454 resizeR(x, y);
455 // Resize -> resize cursor.
456 _Cursor = Cur_Resize_BR;
457 break;
458 // Resize Top Right OSD Border.
459 case resize_TR:
460 resizeT(x, y);
461 resizeR(x, y);
462 // Resize -> resize cursor.
463 _Cursor = Cur_Resize_TR;
464 break;
465 // Move the OSD.
466 case resize_move:
467 move(x, y);
468 // Move -> move cursor.
469 _Cursor = Cur_Move;
470 break;
472 default:
473 _Cursor = Cur_None;
474 break;
477 // Give the new OSD size to controls.
478 for(TMapControls::iterator it = _Controls.begin(); it != _Controls.end(); it++)
480 if((*it).second->parent() == 0)
482 float x, y;
483 calculatePos(x, y, (*it).second->origin());
484 (*it).second->ref(x, y, _W_Display, _H_Display);
489 used = true;
491 else
493 switch(_OSD_Mode)
495 // In Locked mode, the OSD mode can't change.
496 case locked:
497 // OSD locked -> no cursor needed by the OSD.
498 _Cursor = Cur_None;
499 break;
501 // Else the OSD mode changes according to the mouse position.
502 default:
503 // Check the cursor is inside the OSD.
504 if(x>=_X_Display && x<_X_Display+_W_Display && y>=_Y_Display && y<_Y_Display+_H_Display)
506 // Change the cursor look according to its position.
507 // Get the window size.
508 uint32 w, h;
509 CInterfMngr::getWindowSize(w, h);
511 float cornerSizeX = _RS_W+_TB_H/(float)w;
512 float cornerSizeY = _RS_H+_TB_H/(float)h;
514 enum TXState
516 X_0 = 0x00,
517 X_1 = 0x01,
518 X_2 = 0x02,
519 X_3 = 0x03,
520 X_4 = 0x04
523 enum TYState
525 Y_0 = 0x00,
526 Y_1 = 0x10,
527 Y_2 = 0x20,
528 Y_3 = 0x30,
529 Y_4 = 0x40
532 TXState x_State;
533 TYState y_State;
535 // X POSITION in the OSD.
536 // X is in the right part of the OSD (move, resize right, or resize right corners)
537 if(x >= _X_Display+_W_Display-cornerSizeX)
539 // Resize right or right corners.
540 if(x >= _X_Display+_W_Display-_RS_W)
541 x_State = X_4;
542 // Move or resize right corners.
543 else
544 x_State = X_3;
546 // X is in the left part of the OSD (move, resize left, or resize left corners)
547 else if(x < _X_Display+cornerSizeX)
549 // Resize left or left corners.
550 if(x < _X_Display+_RS_W)
551 x_State = X_0;
552 // Move or resize left corners.
553 else
554 x_State = X_1;
556 // X is in the middle part of the OSD (move, resize top or bottom).
557 else
558 x_State = X_2;
562 // Y POSITION in the OSD.
563 // Y is in the Top part of the OSD (move, resize top, or resize top corners)
564 if(y >= _Y_Display+_H_Display-cornerSizeY)
566 // Resize top or top corners.
567 if(y >= _Y_Display+_H_Display-_RS_H)
568 y_State = Y_4;
569 // Move or resize top corners.
570 else
571 y_State = Y_3;
573 // Y is in the bottom part of the OSD (move, resize bottom, or resize bottom corners)
574 else if(y < _Y_Display+cornerSizeY)
576 // Resize bottom or bottm corners.
577 if(y < _Y_Display+_RS_H)
578 y_State = Y_0;
579 // Move or resize bottom corners.
580 else
581 y_State = Y_1;
583 // Y is in the middle part of the OSD (move, resize left or right).
584 else
585 y_State = Y_2;
588 // Determine the Resize Mode.
589 switch(x_State | y_State)
591 // Left Bottom corner
592 case X_1|Y_0:
593 case X_0|Y_0:
594 case X_0|Y_1:
595 _Cursor = Cur_Resize_BL;
596 break;
597 // Left side
598 case X_0|Y_2:
599 _Cursor = Cur_Resize_L;
600 break;
601 // Left Top corner
602 case X_0|Y_3:
603 case X_0|Y_4:
604 case X_1|Y_4:
605 _Cursor = Cur_Resize_TL;
606 break;
607 // Top Side.
608 case X_2|Y_4:
609 _Cursor = Cur_Resize_T;
610 break;
611 // Right Top Corner.
612 case X_3|Y_4:
613 case X_4|Y_4:
614 case X_4|Y_3:
615 _Cursor = Cur_Resize_TR;
616 break;
617 // Right Side.
618 case X_4|Y_2:
619 _Cursor = Cur_Resize_R;
620 break;
621 // Right Bottom Corner.
622 case X_4|Y_1:
623 case X_4|Y_0:
624 case X_3|Y_0:
625 _Cursor = Cur_Resize_BR;
626 break;
627 // Bottom Side.
628 case X_2|Y_0:
629 _Cursor = Cur_Resize_B;
630 break;
631 // Move Area
632 case X_1|Y_3:
633 case X_2|Y_3:
634 case X_3|Y_3:
635 _Cursor = Cur_Move;
636 break;
637 // Inside Area
638 default:
639 _Cursor = Cur_None;
640 break;
644 // Change the display of the OSD according to the cursor position.
645 testMode(x, y, _X_Display+_RS_W*2, _Y_Display+_RS_H*2, _X_Display+_W_Display-_RS_W*2, _Y_Display+_H_Display-_TB_H_Display-_RS_H*2);
646 // ...
647 used = true;
649 else
651 _OSD_Mode = none;
652 // Cursor outside the OSD -> no cursor needed by the OSD.
653 _Cursor = Cur_None;
655 break;
659 else
661 // Manage the OSD mode when the OSD do not have the Focus.
662 switch(_OSD_Mode)
664 // In locked mode the mode do not change.
665 case locked:
666 break;
668 // Else the OSD mode changes to "none".
669 default:
670 _OSD_Mode = none;
671 break;
674 // OSD do not have any interaction -> no cursor.
675 _Cursor = Cur_None;
679 // call the mouseMove() method on every child control
680 TListControl::iterator itControl;
681 const TListControl::iterator itControlEnd = _Children.end();
683 for (itControl = _Children.begin() ; itControl != itControlEnd ; ++itControl)
685 nlassert(*itControl);
686 // only send the mouse move event to controls with show = true
687 if ( (*itControl)->show() )
688 (*itControl)->mouseMove( x, y );
692 // Return if the OSD as react.
693 return used;
694 }// update //
697 //-----------------------------------------------
698 // cursor :
699 // Return the cursor used by the OSD at the moment.
700 // \return ECursor : 'Cur_None' if no cursor needed for the OSD.
701 // \warning This method should be called after the update one to be up to date.
702 //-----------------------------------------------
703 COSD::ECursor COSD::cursor()
705 // Is the OSD is not visible -> no cursor needed;
706 if(!_Show)
707 return Cur_None;
709 // Return the cursor used for the OSD at the moment.
710 return _Cursor;
711 }// cursor //
714 //-----------------------------------------------
715 // click :
716 // Manage the mouse click.
717 //-----------------------------------------------
718 void COSD::click(float x, float y, bool &taken)
720 // Is the OSD is not visible -> return;
721 if(!_Show)
722 return;
724 // if pop_up and cick was outside the window bounds: destroy that window
725 if ( _PopUp )
727 if ( (x < _X_Display) || (x >= _X_Display + _W_Display) || (y < _Y_Display) || (y >= _Y_Display + _H_Display) )
729 CInterfMngr::deleteOSD( this->_Id);
730 return;
734 _OffsetX = x-_X_Display;
735 _OffsetY = y-_Y_Display;
736 _OffsetW = x-(_X_Display+_W_Display);
737 _OffsetH = y-(_Y_Display+_H_Display);
739 // If some resize operations are in progress -> Stop resize.
740 if(_RS_Mode != no_resize)
742 _RS_Mode = no_resize;
743 taken = true;
745 else if (!taken)
748 // Look if the OSD will be resized.
749 switch(_OSD_Mode)
751 // In some _OSD_Mode the aspect OSD can change -> test if it changes.
752 case resizable:
753 case movable:
754 // Select the right resize mode -> mode != no_resize -> click = true.
755 if(resizeMode(x, y) != TResize::no_resize)
756 taken = true;
757 break;
761 // Dispatch the click in the controls.
762 const TListControl::iterator itE = _Children.end();
763 for(TListControl::iterator it = _Children.begin(); it != itE ; ++it)
765 // only send the click event to controls with show = true
766 if ( (*it)->show() )
767 (*it)->click(x, y, taken);
769 }// click //
776 //-----------------------------------------------
777 // clickRight :
778 // Manage the mouse right click.
779 //-----------------------------------------------
780 void COSD::clickRight(float x, float y, bool &taken)
782 // Is the OSD is not visible -> return;
783 if(!_Show)
784 return;
786 // if pop_up and cick was outside the window bounds: destroy that window
787 if ( _PopUp && ( (x < _X_Display) || (x >= _X_Display + _W_Display) || (y < _Y_Display) || (y >= _Y_Display + _H_Display) ) )
789 CInterfMngr::deleteOSD( this->_Id);
790 return;
793 _OffsetX = x-_X_Display;
794 _OffsetY = y-_Y_Display;
795 _OffsetW = x-(_X_Display+_W_Display);
796 _OffsetH = y-(_Y_Display+_H_Display);
798 // If some resize operations are in progress -> Stop resize.
799 if(_RS_Mode != no_resize)
801 _RS_Mode = no_resize;
802 _OSD_Mode = locked;
803 taken = true;
806 // Dispatch the click in the controls.
807 const TListControl::iterator itE = _Children.end();
808 for(TListControl::iterator it = _Children.begin(); it != itE ; ++it)
810 // only send the click event to controls with show = true
811 if ( (*it)->show() )
812 (*it)->clickRight(x, y, taken);
815 // Lock/Unlock the OSD
816 if(!taken)
818 // Check that the cursor is in the OSD.
819 if((x >= _X_Display) && (x < _X_Display + _W_Display) && (y >= _Y_Display) && (y < _Y_Display + _H_Display) )
821 if(_OSD_Mode != locked)
822 _OSD_Mode = locked;
823 else
824 _OSD_Mode = none;
826 taken = true;
829 }// clickRight //
835 //-----------------------------------------------
836 // resizeL :
837 // Resize the Left border of the OSD.
838 //-----------------------------------------------
839 void COSD::resizeL(float x, float y)
841 uint32 width, height;
842 CInterfMngr::getWindowSize(width, height);
844 const float wMin = _W_Min / width;
846 float xTmp = _X_Display + _W_Display;
848 _X_Display = x - _OffsetX;
850 if( _X_Display > xTmp - wMin )
851 _X_Display = xTmp - wMin;
853 _X = _X_Display;
854 _W_Display = xTmp - _X_Display;
855 _W_Pixel = _W_Display*width;
856 }// resizeL //
858 //-----------------------------------------------
859 // resizeR :
860 // Resize the Right border of the OSD.
861 //-----------------------------------------------
862 void COSD::resizeR(float x, float y)
864 uint32 width, height;
865 CInterfMngr::getWindowSize(width, height);
867 const float wMin = _W_Min / width;
869 _W_Display = x - _OffsetW - _X_Display;
870 if(_W_Display < wMin )
871 _W_Display = wMin;
873 _W_Pixel = _W_Display*width;
874 }// resizeR //
876 //-----------------------------------------------
877 // resizeB :
878 // Resize the Bottom border of the OSD.
879 //-----------------------------------------------
880 void COSD::resizeB(float x, float y)
882 uint32 width, height;
883 CInterfMngr::getWindowSize(width, height);
885 const float hMin = _H_Min / height;
887 float yTmp = _Y_Display + _H_Display;
888 _Y_Display = y-_OffsetY;
889 if(_Y_Display > yTmp - hMin )
890 _Y_Display = yTmp - hMin;
892 _Y = _Y_Display;
893 _H_Display = yTmp - _Y_Display;
894 _H_Pixel = _H_Display*height;
895 }// resizeB //
897 //-----------------------------------------------
898 // resizeT :
899 // Resize the Top border of the OSD.
900 //-----------------------------------------------
901 void COSD::resizeT(float x, float y)
903 uint32 width, height;
904 CInterfMngr::getWindowSize(width, height);
906 const float hMin = _H_Min / height;
908 _H_Display = y - _OffsetH - _Y_Display;
909 if(_H_Display < hMin )
910 _H_Display = hMin;
912 _H_Pixel = _H_Display*height;
913 }// resizeT //
915 //-----------------------------------------------
916 // move :
917 // Move the OSD.
918 //-----------------------------------------------
919 void COSD::move(float x, float y)
921 _X_Display = x-_OffsetX;
922 _Y_Display = y-_OffsetY;
923 _X = _X_Display;
924 _Y = _Y_Display;
925 }// move //
931 //-----------------------------------------------
932 // testMode :
933 // Test the mode of the OSD.
934 //-----------------------------------------------
935 void COSD::testMode(float x, float y, float rectX0, float rectY0, float rectX1, float rectY1)
937 if(y>rectY1)
938 _OSD_Mode = movable;
939 else
941 if(x < rectX0 || x > rectX1 || y < rectY0)
942 _OSD_Mode = resizable;
943 else
944 _OSD_Mode = selected;
946 }// testMode //
950 /////////
951 // OSD //
952 //-----------------------------------------------
953 // osdSetPosition :
954 // Change the OSD Position.
955 //-----------------------------------------------
956 void COSD::osdSetPosition(float x, float y)
958 _X = _X_Display = x;
959 _Y = _Y_Display = y;
961 // resize the other controls.
962 for(TMapControls::iterator it = _Controls.begin(); it != _Controls.end(); it++)
964 // If the control as a reference different than the OSD -> the Reference will resize this control.
965 if((*it).second->parent() == 0)
967 float x0, y0;
968 calculatePos(x0, y0, (*it).second->origin());
969 (*it).second->ref(x0, y0, _W_Display, _H_Display);
972 }// osdSetPosition //
974 //-----------------------------------------------
975 // osdGetPosition :
976 // Return the OSD Position.
977 //-----------------------------------------------
978 void COSD::osdGetPosition(float &x, float &y) const
980 x = _X_Display;
981 y = _Y_Display;
982 }// osdGetPosition //
984 //-----------------------------------------------
985 // osdGetSize :
986 // Change the OSD Size (between 0-1).
987 //-----------------------------------------------
988 void COSD::osdSetSize(float w, float h)
990 uint32 width, height;
991 CInterfMngr::getWindowSize(width, height);
993 _W_Display = w;
994 _H_Display = h;
995 _W_Pixel = _W_Display*width;
996 _H_Pixel = _H_Display*height;
998 // resize the other controls.
999 for(TMapControls::iterator it = _Controls.begin(); it != _Controls.end(); it++)
1001 // If the control as a reference different than the OSD -> the Reference will resize this control.
1002 if((*it).second->parent() == 0)
1004 float x0, y0;
1005 calculatePos(x0, y0, (*it).second->origin());
1006 (*it).second->ref(x0, y0, _W_Display, _H_Display);
1009 }// osdGetSize //
1011 //-----------------------------------------------
1012 // osdGetSize :
1013 // Return the OSD Size (between 0-1).
1014 //-----------------------------------------------
1015 void COSD::osdGetSize(float &w, float &h) const
1017 w = _W_Display;
1018 h = _H_Display;
1019 }// osdGetSize //
1021 //-----------------------------------------------
1022 // osdMode :
1023 // Change the OSD Mode (locked, resize, selected, etc.)
1024 //-----------------------------------------------
1025 void COSD::osdMode(TMode osdMode)
1027 _OSD_Mode = osdMode;
1028 }// osdMode //
1030 //-----------------------------------------------
1031 // osdMode :
1032 // Return the current OSD Mode.
1033 //-----------------------------------------------
1034 COSD::TMode COSD::osdMode() const
1036 return _OSD_Mode;
1037 }// osdMode //
1039 //-----------------------------------------------
1040 // osdName :
1041 // Change the OSD Name.
1042 //-----------------------------------------------
1043 void COSD::osdName(const ucstring &osdName)
1045 _OSD_Name = osdName;
1046 }// osdName //
1048 //-----------------------------------------------
1049 // osdName :
1050 // Return the OSD Name.
1051 //-----------------------------------------------
1052 ucstring COSD::osdName() const
1054 return _OSD_Name;
1055 }// osdName //
1057 //-----------------------------------------------
1058 // updateFunc :
1059 // Set the update Function.
1060 //-----------------------------------------------
1061 void COSD::osdUpdateFunc(uint updateFunc)
1063 _OSD_Update_Func = osdUpdateFunc;
1064 }// updateFunc //
1066 //-----------------------------------------------
1067 // updateFunc :
1068 // Get the update Function.
1069 //-----------------------------------------------
1070 uint COSD::osdUpdateFunc() const
1072 return _OSD_Update_Func;
1073 }// updateFunc //
1076 ////////////////
1077 // BACKGROUND //
1078 //-----------------------------------------------
1079 // bgMode :
1080 // Set the Background display mode.
1081 void COSD::bgMode(TBG mode)
1082 //-----------------------------------------------
1084 _BG_Mode = mode;
1085 }// bgMode //
1087 //-----------------------------------------------
1088 // bgMode :
1089 // Get the Background display mode.
1090 //-----------------------------------------------
1091 COSD::TBG COSD::bgMode() const
1093 return _BG_Mode;
1094 }// bgMode //
1096 //-----------------------------------------------
1097 // bg :
1098 // Set the texture Id for the Background.
1099 //-----------------------------------------------
1100 void COSD::bg(uint b)
1102 _BG = b;
1103 }// bg //
1105 //-----------------------------------------------
1106 // bg :
1107 // Get background Id.
1108 //-----------------------------------------------
1109 uint COSD::bg() const
1111 return _BG;
1112 }// bg //
1114 //-----------------------------------------------
1115 // bgColor :
1116 // Set the Background RGBA.
1117 //-----------------------------------------------
1118 void COSD::bgColor(const CRGBA &bRGBA)
1120 _BG_Color = bRGBA;
1121 }// bgColor //
1123 //-----------------------------------------------
1124 // bgColor :
1125 // Get the background RGBA.
1126 //-----------------------------------------------
1127 CRGBA COSD::bgColor() const
1129 return _BG_Color;
1130 }// bgColor //
1133 ///////////////
1134 // TITLE BAR //
1135 //-----------------------------------------------
1136 // tbMode :
1137 // Set the Title Bar display mode.
1138 //-----------------------------------------------
1139 void COSD::tbMode(TTB mode)
1141 _TB_Mode = mode;
1142 }// tbMode //
1144 //-----------------------------------------------
1145 // tbMode :
1146 // Get the Title Bar display mode.
1147 //-----------------------------------------------
1148 COSD::TTB COSD::tbMode() const
1150 return _TB_Mode;
1151 }// tbMode //
1153 //-----------------------------------------------
1154 // tb :
1155 // Set the texture Id for the Title Bar.
1156 //-----------------------------------------------
1157 void COSD::tb(uint t)
1159 _TB = t;
1160 }// tb //
1162 //-----------------------------------------------
1163 // tb :
1164 // Get Title Bar Id.
1165 //-----------------------------------------------
1166 uint COSD::tb() const
1168 return _TB;
1169 }// tb //
1171 //-----------------------------------------------
1172 // tbColor :
1173 // Set the Title Bar RGBA.
1174 //-----------------------------------------------
1175 void COSD::tbColor(const CRGBA &tRGBA)
1177 _TB_Color = tRGBA;
1178 }// tbColor //
1180 //-----------------------------------------------
1181 // tbColor :
1182 // Get the Title Bar RGBA.
1183 //-----------------------------------------------
1184 CRGBA COSD::tbColor() const
1186 return _TB_Color;
1187 }// tbColor //
1189 //-----------------------------------------------
1190 // tbHeight :
1191 // Set Title Bar Height (in Pixel)
1192 //-----------------------------------------------
1193 void COSD::tbHeight(float height)
1195 uint32 w, h;
1196 CInterfMngr::getWindowSize(w, h);
1198 _TB_H = height;
1199 // Calculate the Title Bar height for Display.
1200 _TB_H_Display = _TB_H/h;
1202 }// tbHeight //
1204 //-----------------------------------------------
1205 // tbHeight :
1206 // Get Title Bar Height (in Pixel)
1207 //-----------------------------------------------
1208 float COSD::tbHeight() const
1210 return _TB_H;
1211 }// tbHeight //
1213 //-----------------------------------------------
1214 // pen :
1215 // Set the Pen for the Title Bar.
1216 //-----------------------------------------------
1217 void COSD::tbPen(const CPen &pen)
1219 _TB_Pen = pen;
1220 }// pen //
1222 //-----------------------------------------------
1223 // pen :
1224 // Get the Pen of the Title Bar.
1225 //-----------------------------------------------
1226 CPen COSD::tbPen() const
1228 return _TB_Pen;
1229 }// pen //
1232 ///////////////
1233 // HIGHLIGHT //
1234 //-----------------------------------------------
1235 // hlColor :
1236 // Set the HighLight Color.
1237 //-----------------------------------------------
1238 void COSD::hlColor(const CRGBA &hlColor)
1240 _HL_Color = hlColor;
1241 }// hlColor //
1243 //-----------------------------------------------
1244 // hlColor :
1245 // Get the HighLight Color.
1246 //-----------------------------------------------
1247 CRGBA COSD::hlColor() const
1249 return _HL_Color;
1250 }// hlColor //
1252 //-----------------------------------------------
1253 // hlSize :
1254 // Set the HighLight Size (in Pixel).
1255 //-----------------------------------------------
1256 void COSD::hlSize(float hlSize)
1258 uint32 w, h;
1259 CInterfMngr::getWindowSize(w, h);
1261 _HL_Size = hlSize;
1262 // Calculate borders for the HighLight.
1263 _HL_W = _HL_Size/w; // Left and Right.
1264 _HL_H = _HL_Size/h; // Bottom and Top.
1265 }// hlSize //
1267 //-----------------------------------------------
1268 // hlSize :
1269 // Get the HighLight Size (in Pixel).
1270 //-----------------------------------------------
1271 float COSD::hlSize() const
1273 return _HL_Size;
1274 }// hlSize //
1277 ////////////
1278 // RESIZE //
1279 //-----------------------------------------------
1280 // rsMode :
1281 // Set the Resize Mode.
1282 //-----------------------------------------------
1283 void COSD::rsMode(TResize rsMode)
1285 _RS_Mode = rsMode;
1286 }// rsMode //
1288 //-----------------------------------------------
1289 // rsMode :
1290 // Get the Resize Mode.
1291 //-----------------------------------------------
1292 COSD::TResize COSD::rsMode() const
1294 return _RS_Mode;
1295 }// rsMode //
1297 //-----------------------------------------------
1298 // rsColor :
1299 // Set Resize borders Color
1300 //-----------------------------------------------
1301 void COSD::rsColor(CRGBA rsColor)
1303 _RS_Color = rsColor;
1304 }// rsColor //
1306 //-----------------------------------------------
1307 // rsColor :
1308 // Get Resize borders Color
1309 //-----------------------------------------------
1310 CRGBA COSD::rsColor() const
1312 return _RS_Color;
1313 }// rsColor //
1315 //-----------------------------------------------
1316 // rsSize :
1317 // Set Resize size (in pixel).
1318 //-----------------------------------------------
1319 void COSD::rsSize(float rsSize)
1321 uint32 w, h;
1322 CInterfMngr::getWindowSize(w, h);
1324 _RS_Size = rsSize;
1325 // Calculate borders for the Resize.
1326 _RS_W = _RS_Size/w; // Left and Right.
1327 _RS_H = _RS_Size/h; // Bottom and Top.
1328 }// rsSize //
1330 //-----------------------------------------------
1331 // rsSize :
1332 // Get Resize size (in pixel).
1333 //-----------------------------------------------
1334 float COSD::rsSize() const
1336 return _RS_Size;
1337 }// rsSize //
1343 //-----------------------------------------------
1344 // getCtrl :
1345 // Return the pointer of the control "id".
1346 //-----------------------------------------------
1347 CControl * COSD::getCtrl(uint id)
1349 TMapControls::iterator it = _Controls.find(id);
1351 if(it != _Controls.end())
1352 return (*it).second;
1353 else
1354 return 0;
1355 }// getCtrl //
1358 //-----------------------------------------------
1359 // addChild :
1360 // Add a control.
1361 //-----------------------------------------------
1362 void COSD::addChild(uint idCtrl, CControl *ctrl)
1364 // ...
1365 _Controls.insert(TMapControls::value_type(idCtrl, ctrl));
1366 // The list of control in order to display.
1367 _Children.push_front(ctrl);
1368 }// addChild //
1371 //-----------------------------------------------
1372 // delChild :
1373 // Delete a control by the Id.
1374 //-----------------------------------------------
1375 void COSD::delChild(uint idCtrl)
1377 TMapControls::iterator it = _Controls.find(idCtrl);
1378 if(it != _Controls.end())
1380 CControl *ctrl = (*it).second;
1382 // Erase control.
1383 _Controls.erase(it);
1384 // Check if the control is allocated.
1385 if(ctrl)
1387 // Erase Control.
1388 for(TListControl::iterator itChild = _Children.begin(); itChild != _Children.end(); ++itChild)
1390 if((*itChild) == ctrl)
1392 _Children.erase(itChild);
1393 break;
1396 // Delete Control.
1397 // delete ctrl;
1398 // ctrl = 0;
1401 }// delChild //
1407 //-----------------------------------------------
1408 // removeFromChildren :
1409 // Add a control.
1410 //-----------------------------------------------
1411 void COSD::removeFromChildren(uint idCtrl)
1413 TMapControls::iterator it = _Controls.find(idCtrl);
1414 if(it != _Controls.end())
1416 CControl *ctrl = (*it).second;
1418 // Check if the control is allocated.
1419 if(ctrl)
1421 // Erase Control.
1422 for(TListControl::iterator itChild = _Children.begin(); itChild != _Children.end(); ++itChild)
1424 if((*itChild) == ctrl)
1426 _Children.erase(itChild);
1427 break;
1432 }// removeFromChildren //
1435 //-----------------------------------------------
1436 // calculatePos :
1437 // Calculate a position according to the origin.
1438 //-----------------------------------------------
1439 void COSD::calculatePos(float &x, float &y, CControl::THotSpot origin)
1441 switch(origin)
1443 case CControl::HS_TL:
1444 x = _X_Display;
1445 y = _Y_Display+_H_Display;
1446 break;
1447 case CControl::HS_TM:
1448 x = _X_Display+_W_Display/2.f;
1449 y = _Y_Display+_H_Display;
1450 break;
1451 case CControl::HS_TR:
1452 x = _X_Display+_W_Display;
1453 y = _Y_Display+_H_Display;
1454 break;
1456 case CControl::HS_ML:
1457 x = _X_Display;
1458 y = _Y_Display+_H_Display/2.f;
1459 break;
1460 case CControl::HS_MM:
1461 x = _X_Display+_W_Display/2.f;
1462 y = _Y_Display+_H_Display/2.f;
1463 break;
1464 case CControl::HS_MR:
1465 x = _X_Display+_W_Display;
1466 y = _Y_Display+_H_Display/2.f;
1467 break;
1469 case CControl::HS_BL:
1470 x = _X_Display;
1471 y = _Y_Display;
1472 break;
1473 case CControl::HS_BM:
1474 x = _X_Display+_W_Display/2.f;
1475 y = _Y_Display;
1476 break;
1477 case CControl::HS_BR:
1478 x = _X_Display+_W_Display;
1479 y = _Y_Display;
1480 break;
1482 }// calculatePos //
1485 //-----------------------------------------------
1486 // calculateDisplay :
1487 // Calculate the Display X, Y, Width, Height.
1488 //-----------------------------------------------
1489 void COSD::calculateDisplay()
1491 uint32 w, h;
1492 CInterfMngr::getWindowSize(w, h);
1495 // Calculate the Title Bar height for Display.
1496 _TB_H_Display = _TB_H/h;
1497 // Calculate borders for the Resize.
1498 _RS_W = _RS_Size/w; // Left and Right.
1499 _RS_H = _RS_Size/h; // Bottom and Top.
1500 // Calculate borders for the HighLight.
1501 _HL_W = _HL_Size/w; // Left and Right.
1502 _HL_H = _HL_Size/h; // Bottom and Top.
1504 // Calculate the display Width and Height.
1505 if(w!=0)
1506 _W_Display = _W_Pixel/w; //_W*_W_Ref + _W_Pixel/w;
1507 else
1508 _W_Display = 0.f; //_W*_W_Ref;
1510 if(h!=0)
1511 _H_Display = _H_Pixel/h; //_H*_H_Ref + _H_Pixel/h;
1512 else
1513 _H_Display = 0.f; //_H*_H_Ref;
1515 // // Calculate the HotSpot.
1516 // calculateHS();
1518 _X_Display = _X; //_X_Ref + _X*_W_Ref + _X_Pixel/w + _X_HotSpot;
1519 _Y_Display = _Y; //_Y_Ref + _Y*_H_Ref + _Y_Pixel/h + _Y_HotSpot;
1520 }// calculateDisplay //
1525 ///////////////////////////
1526 // OPERATIONS ON THE OSD //
1527 ///////////////////////////
1528 //-----------------------------------------------
1529 // testInRect :
1530 // Function to test if a coordinate is in the rect.
1531 //-----------------------------------------------
1532 bool COSD::testInRect(float x, float y, float rectX0, float rectY0, float rectX1, float rectY1)
1534 if(x>=rectX0 && x<rectX1 && y>=rectY0 && y<rectY1)
1535 return true;
1536 return false;
1537 }// testInRect //
1540 //-----------------------------------------------
1541 // resizeMode :
1542 // Determine the Resize Mode.
1543 //-----------------------------------------------
1544 bool COSD::resizeMode(float x, float y)
1546 // Get the window size.
1547 uint32 w, h;
1548 CInterfMngr::getWindowSize(w, h);
1550 float cornerSizeX = _RS_W+_TB_H/(float)w;
1551 float cornerSizeY = _RS_H+_TB_H/(float)h;
1553 enum TXState
1555 X_0 = 0x00,
1556 X_1 = 0x01,
1557 X_2 = 0x02,
1558 X_3 = 0x03,
1559 X_4 = 0x04
1562 enum TYState
1564 Y_0 = 0x00,
1565 Y_1 = 0x10,
1566 Y_2 = 0x20,
1567 Y_3 = 0x30,
1568 Y_4 = 0x40
1571 TXState x_State;
1572 TYState y_State;
1574 // X POSITION in the OSD.
1575 // X is in the right part of the OSD (move, resize right, or resize right corners)
1576 if(x >= _X_Display+_W_Display-cornerSizeX)
1578 // Resize right or right corners.
1579 if(x >= _X_Display+_W_Display-_RS_W)
1580 x_State = X_4;
1581 // Move or resize right corners.
1582 else
1583 x_State = X_3;
1585 // X is in the left part of the OSD (move, resize left, or resize left corners)
1586 else if(x < _X_Display+cornerSizeX)
1588 // Resize left or left corners.
1589 if(x < _X_Display+_RS_W)
1590 x_State = X_0;
1591 // Move or resize left corners.
1592 else
1593 x_State = X_1;
1595 // X is in the middle part of the OSD (move, resize top or bottom).
1596 else
1597 x_State = X_2;
1601 // Y POSITION in the OSD.
1602 // Y is in the Top part of the OSD (move, resize top, or resize top corners)
1603 if(y >= _Y_Display+_H_Display-cornerSizeY)
1605 // Resize top or top corners.
1606 if(y >= _Y_Display+_H_Display-_RS_H)
1607 y_State = Y_4;
1608 // Move or resize top corners.
1609 else
1610 y_State = Y_3;
1612 // Y is in the bottom part of the OSD (move, resize bottom, or resize bottom corners)
1613 else if(y < _Y_Display+cornerSizeY)
1615 // Resize bottom or bottm corners.
1616 if(y < _Y_Display+_RS_H)
1617 y_State = Y_0;
1618 // Move or resize bottom corners.
1619 else
1620 y_State = Y_1;
1622 // Y is in the middle part of the OSD (move, resize left or right).
1623 else
1624 y_State = Y_2;
1627 bool resize = true;
1628 // Determine the Resize Mode.
1629 switch(x_State | y_State)
1631 // Left Bottom corner
1632 case X_1|Y_0:
1633 case X_0|Y_0:
1634 case X_0|Y_1:
1635 _RS_Mode = resize_BL;
1636 break;
1637 // Left side
1638 case X_0|Y_2:
1639 _RS_Mode = resize_L;
1640 break;
1641 // Left Top corner
1642 case X_0|Y_3:
1643 case X_0|Y_4:
1644 case X_1|Y_4:
1645 _RS_Mode = resize_TL;
1646 break;
1647 // Top Side.
1648 case X_2|Y_4:
1649 _RS_Mode = resize_T;
1650 break;
1651 // Right Top Corner.
1652 case X_3|Y_4:
1653 case X_4|Y_4:
1654 case X_4|Y_3:
1655 _RS_Mode = resize_TR;
1656 break;
1657 // Right Side.
1658 case X_4|Y_2:
1659 _RS_Mode = resize_R;
1660 break;
1661 // Right Bottom Corner.
1662 case X_4|Y_1:
1663 case X_4|Y_0:
1664 case X_3|Y_0:
1665 _RS_Mode = resize_BR;
1666 break;
1667 // Bottom Side.
1668 case X_2|Y_0:
1669 _RS_Mode = resize_B;
1670 break;
1671 // Move Area
1672 case X_1|Y_3:
1673 case X_2|Y_3:
1674 case X_3|Y_3:
1675 _RS_Mode = resize_move;
1676 break;
1677 // Inside Area
1678 default:
1679 _RS_Mode = no_resize;
1680 resize = false;
1681 break;
1684 return resize;
1685 }// resizeMode //
1689 ////////////
1690 // SCRIPT //
1691 ////////////
1692 //-----------------------------------------------
1693 // getText :
1695 //-----------------------------------------------
1696 void COSD::getText(uint idCtrl)
1698 uint idTxt = 0;
1699 uint idPen = 0;
1701 // Lecture de la partie commune du script de control.
1702 CONTROL_SCRIPT_MACRO
1704 // Get the Text.
1705 else if(strcmp(ptr, "Text:") == 0)
1706 idTxt = getInt();
1707 // Get the Pen.
1708 else if(strcmp(ptr, "Pen:") == 0)
1709 idPen = getInt();
1712 // Create the list.
1713 CText *text = new CText(idCtrl, x, y, xPixel, yPixel, CInterfMngr::getText(idTxt), CInterfMngr::getPen(idPen));
1714 if(text)
1716 text->origin(origin);
1717 text->hotSpot(hs);
1718 text->ref(_X_Display, _Y_Display, _W_Display, _H_Display);
1720 if(idParent != 0)
1722 CControl *parent = CInterfMngr::getCtrl(idParent);
1723 if(parent)
1725 parent->addChild(text);
1726 text->parent(parent);
1730 addChild(idCtrl, text);
1732 }// getText //
1734 //-----------------------------------------------
1735 // getCapture :
1737 //-----------------------------------------------
1738 void COSD::getCapture(uint idCtrl)
1740 uint idtexture = 2;
1741 CRGBA rgba(255,255,255,128);
1742 uint numFunc = 0;
1743 uint idPen = 0;
1744 uint idPrompt = 0;
1746 // Lecture de la partie commune du script de control.
1747 CONTROL_SCRIPT_MACRO
1749 // Get the Function.
1750 else if(strcmp(ptr, "Function:") == 0)
1751 numFunc = getInt();
1752 // Get the Pen.
1753 else if(strcmp(ptr, "Pen:") == 0)
1754 idPen = getInt();
1755 // Get the Prompt.
1756 else if(strcmp(ptr, "Prompt:") == 0)
1757 idPrompt = getInt();
1760 // Create the list.
1761 CCapture *capture = new CCapture(idCtrl, x, y, xPixel, yPixel, w, h, wPixel, hPixel, numFunc, CInterfMngr::getPen(idPen));
1762 if(capture)
1764 capture->origin(origin);
1765 capture->hotSpot(hs);
1766 capture->ref(_X_Display, _Y_Display, _W_Display, _H_Display);
1767 capture->setPrompt( CInterfMngr::getText(idPrompt) );
1769 if(idParent != 0)
1771 CControl *parent = CInterfMngr::getCtrl(idParent);
1772 if(parent)
1774 parent->addChild(capture);
1775 capture->parent(parent);
1779 addChild(idCtrl, capture);
1781 }// getCapture //
1784 //-----------------------------------------------
1785 // getButton :
1787 //-----------------------------------------------
1788 void COSD::getButton(uint idCtrl)
1790 uint numFunc = 0;
1791 uint numFuncR = 0;
1792 uint numFuncD = 0;
1794 uint idTxt = 0;
1795 uint idPen = 0;
1797 // Lecture de la partie commune du script de control.
1798 CONTROL_SCRIPT_MACRO
1800 // Get the Function for left click
1801 else if(strcmp(ptr, "Function:") == 0)
1802 numFunc = getInt();
1804 // Get the Function for Right click
1805 else if(strcmp(ptr, "FunctionRight:") == 0)
1806 numFuncR = getInt();
1808 // Get the Function for double click
1809 else if(strcmp(ptr, "FunctionDouble:") == 0)
1810 numFuncD = getInt();
1812 // Get the Text.
1813 else if(strcmp(ptr, "Text:") == 0)
1814 idTxt = getInt();
1816 // Get the Pen.
1817 else if(strcmp(ptr, "Pen:") == 0)
1818 idPen = getInt();
1821 // Create the button.
1822 CButton *button = new CButton(idCtrl, x, y, xPixel, yPixel, w, h, wPixel, hPixel, numFunc, numFuncR, numFuncD, CInterfMngr::getButton(idCtrl));
1823 if(button)
1825 button->origin(origin);
1826 button->hotSpot(hs);
1827 button->ref(_X_Display, _Y_Display, _W_Display, _H_Display);
1828 button->pen(CInterfMngr::getPen(idPen));
1829 if(idTxt != 0)
1830 button->text(CInterfMngr::getText(idTxt));
1832 if(idParent != 0)
1834 CControl *parent = CInterfMngr::getCtrl(idParent);
1835 if(parent)
1837 parent->addChild(button);
1838 button->parent(parent);
1841 addChild(idCtrl, button);
1843 }// getButton //
1846 //-----------------------------------------------
1847 // getRadioButton :
1849 //-----------------------------------------------
1850 void COSD::getRadioButton(uint idCtrl)
1852 uint numFunc = 0;
1853 uint numFuncR = 0;
1854 uint numFuncD = 0;
1856 uint idTxt = 0;
1857 uint idPen = 0;
1859 // Lecture de la partie commune du script de control.
1860 CONTROL_SCRIPT_MACRO
1862 // Get the Function for left click
1863 else if(strcmp(ptr, "Function:") == 0)
1864 numFunc = getInt();
1866 // Get the Function for Right click
1867 else if(strcmp(ptr, "FunctionRight:") == 0)
1868 numFuncR = getInt();
1870 // Get the Function for double click
1871 else if(strcmp(ptr, "FunctionDouble:") == 0)
1872 numFuncD = getInt();
1874 // Get the Text.
1875 else if(strcmp(ptr, "Text:") == 0)
1876 idTxt = getInt();
1878 // Get the Pen.
1879 else if(strcmp(ptr, "Pen:") == 0)
1880 idPen = getInt();
1883 // Create the button.
1884 CRadioButton *button = new CRadioButton(idCtrl, x, y, xPixel, yPixel, w, h, wPixel, hPixel, numFunc, numFuncR, numFuncD, CInterfMngr::getButton(idCtrl));
1885 if(button)
1887 button->origin(origin);
1888 button->hotSpot(hs);
1889 button->ref(_X_Display, _Y_Display, _W_Display, _H_Display);
1890 button->pen(CInterfMngr::getPen(idPen));
1891 if(idTxt != 0)
1892 button->text(CInterfMngr::getText(idTxt));
1894 if(idParent != 0)
1896 CControl *parent = CInterfMngr::getCtrl(idParent);
1897 if(parent)
1899 parent->addChild(button);
1900 button->parent(parent);
1903 addChild(idCtrl, button);
1905 }// getRadioButton //
1908 //-----------------------------------------------
1909 // getRadioController :
1911 //-----------------------------------------------
1912 void COSD::getRadioController(uint idCtrl)
1914 char delimiter[] = "[] \t";
1916 // Create the radio controller.
1917 CRadioController *radioController = new CRadioController(idCtrl);
1918 if(radioController)
1920 uint buttonId;
1921 TMapControls::iterator it;
1923 char *ptr = strtok(NULL, delimiter);
1924 while(ptr != NULL)
1926 // Get all buttons.
1927 if(strcmp(ptr, "Buttons:") == 0)
1929 ptr = strtok(NULL, delimiter);
1930 while((ptr != NULL) && (strcmp(ptr, "End")!=0))
1932 buttonId = atoi(ptr);
1933 it = _Controls.find(buttonId);
1934 if(it != _Controls.end())
1936 if(radioController->add(dynamic_cast<CRadioButton*>((*it).second)) == false)
1938 nlerror("Interface Error : control %d can't be add in the radio button %d", buttonId, idCtrl);
1942 // Next Id.
1943 ptr = strtok(NULL, delimiter);
1947 // Next Token
1948 ptr = strtok(NULL, delimiter);
1951 // Test if there is at least 1 button)
1952 if( radioController->size() > 0)
1954 // Insert the radio controller in the control list.
1955 addChild(idCtrl, radioController);
1957 // No Button -> Destroy Radio Button.
1958 else
1960 delete radioController;
1961 radioController = 0;
1964 }// getRadioController //
1966 //-----------------------------------------------
1967 // getBitmap :
1969 //-----------------------------------------------
1970 void COSD::getBitmap(uint idCtrl)
1972 uint idtexture = 0;
1973 bool tiled = false;
1974 CRGBA rgba;
1976 // Lecture de la partie commune du script de control.
1977 CONTROL_SCRIPT_MACRO
1979 // Get the Texture.
1980 else if(strcmp(ptr, "Texture:") == 0)
1981 idtexture = getInt();
1982 // Get the RGBA.
1983 else if(strcmp(ptr, "RGBA:") == 0)
1984 rgba = getRGBA();
1985 // tiled or stretched
1986 else if(strcmp(ptr, "Tiled:") == 0)
1988 if (getInt() ==1)
1989 tiled = true;
1993 // Create the list.
1994 CBitm *bitmap = new CBitm(idCtrl, x, y, xPixel, yPixel, w, h, wPixel, hPixel, idtexture, rgba);
1995 if(bitmap)
1997 bitmap->tiled( tiled );
1998 bitmap->origin(origin);
1999 bitmap->hotSpot(hs);
2000 bitmap->ref(_X_Display, _Y_Display, _W_Display, _H_Display);
2002 if(idParent != 0)
2004 CControl *parent = CInterfMngr::getCtrl(idParent);
2005 if(parent)
2007 parent->addChild(bitmap);
2008 bitmap->parent(parent);
2012 addChild(idCtrl, bitmap);
2014 }// getBitmap //
2016 //-----------------------------------------------
2017 // getList :
2019 //-----------------------------------------------
2020 void COSD::getList(uint idCtrl)
2022 uint idPen = 0;
2024 uint upTexture = 0;
2025 uint downTexture = 0;
2026 uint scrollBarTexture = 0;
2027 CRGBA scrollBarRgba(255,255,255,255);
2029 // Lecture de la partie commune du script de control.
2030 CONTROL_SCRIPT_MACRO
2032 // Get the Pen.
2033 else if(strcmp(ptr, "Pen:") == 0)
2034 idPen = getInt();
2035 // Get the Texture for the 'up' arrow
2036 else if(strcmp(ptr, "UpTexture:") == 0)
2037 upTexture = getInt();
2038 // Get the Texture for the 'down' arrow
2039 else if(strcmp(ptr, "DownTexture:") == 0)
2040 downTexture = getInt();
2041 // Get the Texture for the scroll bar body
2042 else if(strcmp(ptr, "ScrollBarTexture:") == 0)
2043 scrollBarTexture = getInt();
2044 // Get the RGBA for the scroll bar
2045 else if(strcmp(ptr, "ScrollBarRGBA:") == 0)
2046 scrollBarRgba = getRGBA();
2049 // Create the list.
2050 CList *list = new CList(idCtrl, x, y, xPixel, yPixel, w, h, wPixel, hPixel, CInterfMngr::getPen(idPen));
2051 if(list)
2053 list->origin(origin);
2054 list->hotSpot(hs);
2055 list->ref(_X_Display, _Y_Display, _W_Display, _H_Display);
2057 CScrollBar *scroll = list->getVScroll();
2058 if(scroll)
2060 scroll->setDownArrowTextureOn( downTexture );
2061 scroll->setUpArrowTextureOn( upTexture );
2062 scroll->textureOn( scrollBarTexture );
2063 scroll->setDownArrowTextureOff( downTexture );
2064 scroll->setUpArrowTextureOff( upTexture );
2065 scroll->textureDisable( scrollBarTexture );
2066 scroll->colorOn( scrollBarRgba );
2067 scroll->enable(true);
2070 if(idParent != 0)
2072 CControl *parent = CInterfMngr::getCtrl(idParent);
2073 if(parent)
2075 parent->addChild(list);
2076 list->parent(parent);
2080 addChild(idCtrl, list);
2082 }// getList //
2085 //-----------------------------------------------
2086 // getMultiList :
2088 //-----------------------------------------------
2089 void COSD::getMultiList(uint idCtrl)
2091 uint idtexture = 0;
2092 uint upTexture = 0;
2093 uint downTexture = 0;
2094 uint scrollBarTexture = 0;
2095 uint nbCol = 2;
2096 uint16 spacing = 0;
2097 uint16 lineHeight = 0;
2099 std::vector<float> colSize;
2101 CRGBA rgba(255,255,255,255);
2102 CRGBA scrollBarRgba(255,255,255,255);
2104 uint idPen = 0;
2106 // Lecture de la partie commune du script de control.
2107 CONTROL_SCRIPT_MACRO
2109 // Get the number of columns
2110 else if(strcmp(ptr, "NbColumns:") == 0)
2111 nbCol = getInt();
2113 // Get the columns size.
2114 else if(strcmp(ptr, "ColSize:") == 0)
2115 colSize = getVectorOfFloat(nbCol);
2117 // Get the Pen.
2118 else if(strcmp(ptr, "Pen:") == 0)
2119 idPen = getInt();
2121 // Get the Spacing.
2122 else if(strcmp(ptr, "Spacing:") == 0)
2123 spacing = getInt();
2125 // Get the specified Line Height.
2126 else if(strcmp(ptr, "LineHeight:") == 0)
2127 lineHeight = getInt();
2129 // Get the Texture for the 'up' arrow
2130 else if(strcmp(ptr, "UpTexture:") == 0)
2131 upTexture = getInt();
2132 // Get the Texture for the 'down' arrow
2133 else if(strcmp(ptr, "DownTexture:") == 0)
2134 downTexture = getInt();
2135 // Get the Texture for the scroll bar body
2136 else if(strcmp(ptr, "ScrollBarTexture:") == 0)
2137 scrollBarTexture = getInt();
2138 // Get the RGBA for the scroll bar
2139 else if(strcmp(ptr, "ScrollBarRGBA:") == 0)
2140 scrollBarRgba = getRGBA();
2143 // Create the list.
2144 CMultiList *list = new CMultiList(idCtrl, x, y, xPixel, yPixel, w, h, wPixel, hPixel, CInterfMngr::getPen(idPen), nbCol);
2145 if(list)
2147 list->origin(origin);
2148 list->hotSpot(hs);
2149 list->ref(_X_Display, _Y_Display, _W_Display, _H_Display);
2151 if ( nbCol == colSize.size() )
2152 list->setColSize( colSize );
2154 list->setSpacing( spacing );
2155 list->setLineHeight( lineHeight );
2157 CScrollBar *scroll = list->getVScroll();
2158 if (scroll)
2160 scroll->setDownArrowTextureOn( downTexture );
2161 scroll->setUpArrowTextureOn( upTexture );
2162 scroll->textureOn( scrollBarTexture );
2163 scroll->setDownArrowTextureOff( downTexture );
2164 scroll->setUpArrowTextureOff( upTexture );
2165 scroll->textureDisable( scrollBarTexture );
2166 scroll->colorOn( scrollBarRgba );
2167 scroll->enable(true);
2170 if(idParent != 0)
2172 CControl *parent = CInterfMngr::getCtrl(idParent);
2173 if(parent)
2175 parent->addChild(list);
2176 list->parent(parent);
2180 addChild(idCtrl, list);
2182 }// getMultiList //
2186 //-----------------------------------------------
2187 // getChatBox :
2189 //-----------------------------------------------
2190 void COSD::getChatBox(uint idCtrl)
2192 uint idtexture = 0;
2193 uint upTexture = 0;
2194 uint downTexture = 0;
2195 uint scrollBarTexture = 0;
2196 CRGBA rgba(255,255,255,255);
2197 CRGBA scrollBarRgba(255,255,255,255);
2198 uint idPen = 0;
2199 uint leftFunc = 0;
2200 uint rightFunc = 0;
2202 // Lecture de la partie commune du script de control.
2203 CONTROL_SCRIPT_MACRO
2205 // Get the Pen.
2206 else if(strcmp(ptr, "Pen:") == 0)
2207 idPen = getInt();
2209 // Get the function to execute on left click on player name
2210 else if(strcmp(ptr, "LeftClickFunction:") == 0)
2211 leftFunc = getInt();
2213 // Get the function to execute on left click on player name
2214 else if(strcmp(ptr, "RightClickFunction:") == 0)
2215 rightFunc = getInt();
2216 // Get the Texture for the 'up' arrow
2217 else if(strcmp(ptr, "UpTexture:") == 0)
2218 upTexture = getInt();
2219 // Get the Texture for the 'down' arrow
2220 else if(strcmp(ptr, "DownTexture:") == 0)
2221 downTexture = getInt();
2222 // Get the Texture for the scroll bar body
2223 else if(strcmp(ptr, "ScrollBarTexture:") == 0)
2224 scrollBarTexture = getInt();
2225 // Get the RGBA for the scroll bar
2226 else if(strcmp(ptr, "ScrollBarRGBA:") == 0)
2227 scrollBarRgba = getRGBA();
2230 // Create the list.
2231 CChatControl *chat = new CChatControl(idCtrl, x, y, xPixel, yPixel, w, h, wPixel, hPixel, leftFunc, rightFunc, CInterfMngr::getPen(idPen));
2232 if(chat)
2234 chat->origin(origin);
2235 chat->hotSpot(hs);
2236 chat->ref(_X_Display, _Y_Display, _W_Display, _H_Display);
2238 CScrollBar *scroll = chat->getVScroll();
2239 if (scroll)
2241 scroll->setDownArrowTextureOn( downTexture );
2242 scroll->setUpArrowTextureOn( upTexture );
2243 scroll->textureOn( scrollBarTexture );
2244 scroll->setDownArrowTextureOff( downTexture );
2245 scroll->setUpArrowTextureOff( upTexture );
2246 scroll->textureDisable( scrollBarTexture );
2247 scroll->colorOn( scrollBarRgba );
2248 scroll->enable(true);
2252 if(idParent != 0)
2254 CControl *parent = CInterfMngr::getCtrl(idParent);
2255 if(parent)
2257 parent->addChild(chat);
2258 chat->parent(parent);
2262 addChild(idCtrl, chat);
2264 }// getChatBox //
2267 //-----------------------------------------------
2268 // getCandidateList :
2270 //-----------------------------------------------
2271 void COSD::getCandidateList(uint idCtrl)
2273 uint idtexture = 0;
2274 uint upTexture = 0;
2275 uint downTexture = 0;
2276 uint scrollBarTexture = 0;
2277 uint spacing = 0;
2278 uint lineHeight = 0;
2279 uint leftFunc = 0;
2280 uint rightFunc = 0;
2281 std::vector<float> colSize;
2283 CRGBA rgba(255,255,255,255);
2284 CRGBA selRgba(0,0,0,255);
2285 CRGBA scrollBarRgba(255,255,255,255);
2287 uint idPen = 0;
2289 // Lecture de la partie commune du script de control.
2290 CONTROL_SCRIPT_MACRO
2292 // Get the columns size.
2293 else if(strcmp(ptr, "ColSize:") == 0)
2294 colSize = getVectorOfFloat(2);
2296 // Get the Pen.
2297 else if(strcmp(ptr, "Pen:") == 0)
2298 idPen = getInt();
2300 // Get the Spacing.
2301 else if(strcmp(ptr, "Spacing:") == 0)
2302 spacing = getInt();
2304 // Get the function to execute on left click on candidate name
2305 else if(strcmp(ptr, "LeftClickFunction:") == 0)
2306 leftFunc = getInt();
2308 // Get the function to execute on left click on candidate name
2309 else if(strcmp(ptr, "RightClickFunction:") == 0)
2310 rightFunc = getInt();
2312 // Get the specified Line Height.
2313 else if(strcmp(ptr, "LineHeight:") == 0)
2314 lineHeight = getInt();
2316 // Get the Texture for the 'up' arrow
2317 else if(strcmp(ptr, "UpTexture:") == 0)
2318 upTexture = getInt();
2319 // Get the Texture for the 'down' arrow
2320 else if(strcmp(ptr, "DownTexture:") == 0)
2321 downTexture = getInt();
2322 // Get the Texture for the scroll bar body
2323 else if(strcmp(ptr, "ScrollBarTexture:") == 0)
2324 scrollBarTexture = getInt();
2325 // Get the RGBA for the scroll bar
2326 else if(strcmp(ptr, "ScrollBarRGBA:") == 0)
2327 scrollBarRgba = getRGBA();
2329 // Get the RGBA for the selection box
2330 else if(strcmp(ptr, "SelectionRGBA:") == 0)
2331 selRgba = getRGBA();
2334 // Create the list.
2335 CCandidateList *list = new CCandidateList(idCtrl, x, y, xPixel, yPixel, w, h, wPixel, hPixel, CInterfMngr::getPen(idPen));
2336 if(list)
2338 list->origin(origin);
2339 list->hotSpot(hs);
2340 list->ref(_X_Display, _Y_Display, _W_Display, _H_Display);
2342 if( 2 == colSize.size() )
2343 list->setColSize( colSize );
2345 list->setSpacing( spacing );
2346 list->setLineHeight( lineHeight );
2347 list->setSelectedColor( selRgba );
2348 list->setLeftClickFunction( leftFunc );
2349 list->setRightClickFunction( rightFunc );
2352 CScrollBar *scroll = list->getVScroll();
2353 if (scroll)
2355 scroll->setDownArrowTextureOn( downTexture );
2356 scroll->setUpArrowTextureOn( upTexture );
2357 scroll->textureOn( scrollBarTexture );
2358 scroll->setDownArrowTextureOff( downTexture );
2359 scroll->setUpArrowTextureOff( upTexture );
2360 scroll->textureDisable( scrollBarTexture );
2361 scroll->colorOn( scrollBarRgba );
2362 scroll->enable(true);
2365 if(idParent != 0)
2367 CControl *parent = CInterfMngr::getCtrl(idParent);
2368 if(parent)
2370 parent->addChild(list);
2371 list->parent(parent);
2375 addChild(idCtrl, list);
2377 }// getCandidateList //
2379 //-----------------------------------------------
2380 // getChatInput :
2382 //-----------------------------------------------
2383 void COSD::getChatInput(uint idCtrl)
2385 uint idtexture = 0;
2386 CRGBA rgba;
2387 uint numFunc = 0;
2388 uint idPen = 0;
2390 // Lecture de la partie commune du script de control.
2391 CONTROL_SCRIPT_MACRO
2393 // Get the Function.
2394 else if(strcmp(ptr, "Function:") == 0)
2395 numFunc = getInt();
2396 // Get the Pen.
2397 else if(strcmp(ptr, "Pen:") == 0)
2398 idPen = getInt();
2401 // Create the chat input
2402 CChatInput *chat = new CChatInput(idCtrl, x, y, xPixel, yPixel, w, h, wPixel, hPixel, numFunc, CInterfMngr::getPen(idPen));
2403 if(chat)
2405 chat->origin(origin);
2406 chat->hotSpot(hs);
2407 chat->ref(_X_Display, _Y_Display, _W_Display, _H_Display);
2409 if(idParent != 0)
2411 CControl *parent = CInterfMngr::getCtrl(idParent);
2412 if(parent)
2414 parent->addChild(chat);
2415 chat->parent(parent);
2419 addChild(idCtrl, chat);
2421 }// getChatInput //
2424 //-----------------------------------------------
2425 // getChatInput :
2427 //-----------------------------------------------
2428 void COSD::getChoiceList(uint idCtrl)
2430 uint idPen = 0;
2432 uint upTexture = 0;
2433 uint downTexture = 0;
2434 uint scrollBarTexture = 0;
2435 CRGBA scrollBarRgba(255,255,255,255);
2438 // Lecture de la partie commune du script de control.
2439 CONTROL_SCRIPT_MACRO
2441 // Get the Pen.
2442 else if(strcmp(ptr, "Pen:") == 0)
2443 idPen = getInt();
2444 // Get the Texture for the 'up' arrow
2445 else if(strcmp(ptr, "UpTexture:") == 0)
2446 upTexture = getInt();
2447 // Get the Texture for the 'down' arrow
2448 else if(strcmp(ptr, "DownTexture:") == 0)
2449 downTexture = getInt();
2450 // Get the Texture for the scroll bar body
2451 else if(strcmp(ptr, "ScrollBarTexture:") == 0)
2452 scrollBarTexture = getInt();
2453 // Get the RGBA for the scroll bar
2454 else if(strcmp(ptr, "ScrollBarRGBA:") == 0)
2455 scrollBarRgba = getRGBA();
2458 // Create the chat input
2459 CChoiceList *choiceList = new CChoiceList(idCtrl, x, y, xPixel, yPixel, w, h, wPixel, hPixel, CInterfMngr::getPen(idPen));
2460 if(choiceList)
2462 choiceList->origin(origin);
2463 choiceList->hotSpot(hs);
2464 choiceList->ref(_X_Display, _Y_Display, _W_Display, _H_Display);
2466 CScrollBar *scroll = choiceList->getVScroll();
2467 if (scroll)
2469 scroll->setDownArrowTextureOn( downTexture );
2470 scroll->setUpArrowTextureOn( upTexture );
2471 scroll->textureOn( scrollBarTexture );
2472 scroll->setDownArrowTextureOff( downTexture );
2473 scroll->setUpArrowTextureOff( upTexture );
2474 scroll->textureDisable( scrollBarTexture );
2475 scroll->colorOn( scrollBarRgba );
2476 scroll->enable(true);
2479 if(idParent != 0)
2481 CControl *parent = CInterfMngr::getCtrl(idParent);
2482 if(parent)
2484 parent->addChild(choiceList);
2485 choiceList->parent(parent);
2489 addChild(idCtrl, choiceList);
2491 }// getChatInput //
2494 //-----------------------------------------------
2495 // getHorizontalList :
2497 //-----------------------------------------------
2498 void COSD::getHorizontalList(uint idCtrl)
2500 uint16 spacing = 0;
2501 uint scrollLeftId = 0;
2502 uint scrollRightId = 0;
2503 uint idtexture = 0;
2504 CRGBA rgba(255,255,255,255);
2505 bool tiled = false;
2507 // Lecture de la partie commune du script de control.
2508 CONTROL_SCRIPT_MACRO
2510 // Get the Spacing.
2511 else if(strcmp(ptr, "Spacing:") == 0)
2512 spacing = getInt();
2514 else if(strcmp(ptr, "ScrollLeft:") == 0)
2515 scrollLeftId = getInt();
2517 else if(strcmp(ptr, "ScrollRight:") == 0)
2518 scrollRightId = getInt();
2520 else if(strcmp(ptr, "Controls:") == 0)
2522 ptr = strtok(NULL, delimiter);
2523 while((ptr != NULL) && (strcmp(ptr, "End")!=0))
2525 elts.push_back( atoi(ptr) );
2526 ptr = strtok(NULL, delimiter);
2530 // Get the Texture.
2531 else if(strcmp(ptr, "Texture:") == 0)
2532 idtexture = getInt();
2533 // Get the RGBA.
2534 else if(strcmp(ptr, "RGBA:") == 0)
2535 rgba = getRGBA();
2536 else if(strcmp(ptr, "Tiled:") == 0)
2538 if ( getInt() == 1 )
2539 tiled = true;
2543 // Create the list.
2544 CHorizontalList *list = new CHorizontalList(idCtrl, x, y, xPixel, yPixel, w, h, wPixel, hPixel, spacing, idtexture, rgba);
2545 if(list)
2547 list->tiled( tiled );
2549 std::list< uint16 >::iterator itElts, itEltsEnd = elts.end();
2550 TMapControls::iterator it;
2552 for (itElts = elts.begin() ; itElts != itEltsEnd ; ++itElts )
2554 it = _Controls.find( *itElts );
2555 if(it != _Controls.end())
2557 CControl *ctrl = (*it).second;
2558 // Erase control.
2559 _Controls.erase(it);
2560 // Check if the control is allocated.
2561 if(ctrl)
2563 // add control to the list
2564 list->add( ctrl );
2566 // Erase Control.
2567 for(TListControl::iterator itChild = _Children.begin(); itChild != _Children.end(); ++itChild)
2569 if((*itChild) == ctrl)
2571 _Children.erase(itChild);
2572 break;
2579 // get left scroll bitmap
2580 if (scrollLeftId != 0)
2582 it = _Controls.find( scrollLeftId );
2583 if(it != _Controls.end())
2585 CControl *ctrl = (*it).second;
2586 // Erase control.
2587 //_Controls.erase(it);
2588 if(ctrl)
2590 // add control to the list
2591 list->setLeftScrollBitmap( safe_cast<CBitm*> (ctrl) );
2593 // Erase Control.
2594 for(TListControl::iterator itChild = _Children.begin(); itChild != _Children.end(); ++itChild)
2596 if((*itChild) == ctrl)
2598 _Children.erase(itChild);
2599 break;
2605 // get right scroll bitmap
2606 if (scrollRightId != 0)
2608 it = _Controls.find( scrollRightId );
2609 if(it != _Controls.end())
2611 CControl *ctrl = (*it).second;
2612 // Erase control.
2613 //_Controls.erase(it);
2614 if(ctrl)
2616 // add control to the list
2617 list->setRightScrollBitmap( safe_cast<CBitm*> (ctrl) );
2619 // Erase Control.
2620 for(TListControl::iterator itChild = _Children.begin(); itChild != _Children.end(); ++itChild)
2622 if((*itChild) == ctrl)
2624 _Children.erase(itChild);
2625 break;
2632 list->origin(origin);
2633 list->hotSpot(hs);
2634 list->ref(_X_Display, _Y_Display, _W_Display, _H_Display);
2636 if(idParent != 0)
2638 CControl *parent = CInterfMngr::getCtrl(idParent);
2639 if(parent)
2641 parent->addChild(list);
2642 list->parent(parent);
2646 addChild(idCtrl, list);
2648 }// getHorizontalList //
2651 //-----------------------------------------------
2652 // getControlList :
2654 //-----------------------------------------------
2655 void COSD::getControlList(uint idCtrl)
2657 uint16 spacing = 0;
2658 uint upTexture = 0;
2659 uint downTexture = 0;
2660 uint scrollBarTexture = 0;
2661 CRGBA scrollBarRgba(255,255,255,255);
2663 // Lecture de la partie commune du script de control.
2664 CONTROL_SCRIPT_MACRO
2666 // Get the Spacing.
2667 else if(strcmp(ptr, "Spacing:") == 0)
2668 spacing = getInt();
2670 else if(strcmp(ptr, "Controls:") == 0)
2672 ptr = strtok(NULL, delimiter);
2673 while((ptr != NULL) && (strcmp(ptr, "End")!=0))
2675 elts.push_back( atoi(ptr) );
2676 ptr = strtok(NULL, delimiter);
2679 // Get the Texture for the 'up' arrow
2680 else if(strcmp(ptr, "UpTexture:") == 0)
2681 upTexture = getInt();
2682 // Get the Texture for the 'down' arrow
2683 else if(strcmp(ptr, "DownTexture:") == 0)
2684 downTexture = getInt();
2685 // Get the Texture for the scroll bar body
2686 else if(strcmp(ptr, "ScrollBarTexture:") == 0)
2687 scrollBarTexture = getInt();
2688 // Get the RGBA for the scroll bar
2689 else if(strcmp(ptr, "ScrollBarRGBA:") == 0)
2690 scrollBarRgba = getRGBA();
2694 // Create the list.
2695 CControlList *list = new CControlList(idCtrl, x, y, xPixel, yPixel, w, h, wPixel, hPixel, spacing);
2696 if(list)
2698 CScrollBar *scroll = list->getVScroll();
2699 if (scroll)
2701 scroll->setDownArrowTextureOn( downTexture );
2702 scroll->setUpArrowTextureOn( upTexture );
2703 scroll->textureOn( scrollBarTexture );
2704 scroll->setDownArrowTextureOff( downTexture );
2705 scroll->setUpArrowTextureOff( upTexture );
2706 scroll->textureDisable( scrollBarTexture );
2707 scroll->colorOn( scrollBarRgba );
2708 scroll->enable(true);
2711 std::list< uint16 >::iterator itElts, itEltsEnd = elts.end();
2712 TMapControls::iterator it;
2714 for (itElts = elts.begin() ; itElts != itEltsEnd ; ++itElts )
2716 it = _Controls.find( *itElts );
2717 if(it != _Controls.end())
2719 CControl *ctrl = (*it).second;
2720 // Erase control.
2721 //_Controls.erase(it);
2722 // Check if the control is allocated.
2723 if(ctrl)
2725 // add control to the list
2726 list->add( ctrl );
2728 // Erase Control.
2729 for(TListControl::iterator itChild = _Children.begin(); itChild != _Children.end(); ++itChild)
2731 if((*itChild) == ctrl)
2733 _Children.erase(itChild);
2734 break;
2740 list->origin(origin);
2741 list->hotSpot(hs);
2742 list->ref(_X_Display, _Y_Display, _W_Display, _H_Display);
2744 if(idParent != 0)
2746 CControl *parent = CInterfMngr::getCtrl(idParent);
2747 if(parent)
2749 parent->addChild(list);
2750 list->parent(parent);
2754 addChild(idCtrl, list);
2756 }// getControlList //
2759 //-----------------------------------------------
2760 // getSpellList :
2762 //-----------------------------------------------
2763 void COSD::getSpellList(uint idCtrl)
2765 uint16 spacing = 0;
2766 uint idSpellPen = 0 ;
2767 uint idCommentPen = 0 ;
2768 float buttonW = 0;
2769 float buttonH = 0;
2770 uint leftFunc = 0;
2771 uint rightFunc = 0;
2772 float line_H = 0;
2773 float line_H_Pixel = 0;
2774 uint upTexture = 0;
2775 uint downTexture = 0;
2776 uint scrollBarTexture = 0;
2777 CRGBA scrollBarRgba(255,255,255,255);
2779 // Lecture de la partie commune du script de control.
2780 CONTROL_SCRIPT_MACRO
2782 // Get the Spacing.
2783 else if(strcmp(ptr, "Spacing:") == 0)
2784 spacing = getInt();
2785 // Get the Pen.
2786 else if(strcmp(ptr, "SpellPen:") == 0)
2787 idSpellPen = getInt();
2788 // Get the Pen.
2789 else if(strcmp(ptr, "CommentPen:") == 0)
2790 idCommentPen = getInt();
2791 // Get the button width
2792 else if(strcmp(ptr, "ButtonW:") == 0)
2793 buttonW = getFloat();
2794 // Get the button width
2795 else if(strcmp(ptr, "ButtonH:") == 0)
2796 buttonH = getFloat();
2797 // Get the function to execute on left click on candidate name
2798 else if(strcmp(ptr, "LeftClickFunction:") == 0)
2799 leftFunc = getInt();
2800 // Get the function to execute on left click on candidate name
2801 else if(strcmp(ptr, "RightClickFunction:") == 0)
2802 rightFunc = getInt();
2803 // Get the height of a line in the control (relative to the size of the list)
2804 else if(strcmp(ptr, "Line_H:") == 0)
2805 line_H = getFloat();
2806 // Get the height of a line in the control (in pixels)
2807 else if(strcmp(ptr, "Line_H_Pixel:") == 0)
2808 line_H_Pixel = getFloat();
2809 // Get the Texture for the 'up' arrow
2810 else if(strcmp(ptr, "UpTexture:") == 0)
2811 upTexture = getInt();
2812 // Get the Texture for the 'down' arrow
2813 else if(strcmp(ptr, "DownTexture:") == 0)
2814 downTexture = getInt();
2815 // Get the Texture for the scroll bar body
2816 else if(strcmp(ptr, "ScrollBarTexture:") == 0)
2817 scrollBarTexture = getInt();
2818 // Get the RGBA for the scroll bar
2819 else if(strcmp(ptr, "ScrollBarRGBA:") == 0)
2820 scrollBarRgba = getRGBA();
2823 // Create the list.
2824 CSpellList *list = new CSpellList(idCtrl, x, y, xPixel, yPixel, w, h, wPixel, hPixel, spacing , leftFunc, rightFunc);
2826 if(list)
2828 CScrollBar *scroll = list->getVScroll();
2829 if (scroll)
2831 scroll->setDownArrowTextureOn( downTexture );
2832 scroll->setUpArrowTextureOn( upTexture );
2833 scroll->textureOn( scrollBarTexture );
2834 scroll->setDownArrowTextureOff( downTexture );
2835 scroll->setUpArrowTextureOff( upTexture );
2836 scroll->textureDisable( scrollBarTexture );
2837 scroll->colorOn( scrollBarRgba );
2838 scroll->enable(true);
2841 list->setLineHeight( line_H, line_H_Pixel);
2842 list->setButtonParam( buttonW, buttonH, CInterfMngr::getButton(idCtrl) );
2844 list->setCommentPen( CInterfMngr::getPen(idCommentPen) );
2845 list->setSpellPen( CInterfMngr::getPen(idSpellPen) );
2847 list->origin(origin);
2848 list->hotSpot(hs);
2849 list->ref(_X_Display, _Y_Display, _W_Display, _H_Display);
2851 if(idParent != 0)
2853 CControl *parent = CInterfMngr::getCtrl(idParent);
2854 if(parent)
2856 parent->addChild(list);
2857 list->parent(parent);
2861 addChild(idCtrl, list);
2863 }// getSpellList //
2867 //-----------------------------------------------
2868 // getProgressBar :
2869 //-----------------------------------------------
2870 void COSD::getProgressBar(uint idCtrl)
2872 uint bkgTexture = 0;
2873 uint barTexture = 0;
2874 uint idPen = 0;
2875 uint idText = 0;
2878 uint32 range = 100;
2879 uint32 step = 0;
2881 CRGBA bkgRgba(255,255,255,255);
2882 CRGBA barRgba(255,255,255,255);
2884 // Lecture de la partie commune du script de control.
2885 CONTROL_SCRIPT_MACRO
2887 // Get the Texture for the progress bar
2888 else if(strcmp(ptr, "BarTexture:") == 0)
2889 barTexture = getInt();
2890 // Get the Texture for the background
2891 else if(strcmp(ptr, "BackgroundTexture:") == 0)
2892 bkgTexture = getInt();
2893 // Get the RGBA for the progress bar
2894 else if(strcmp(ptr, "BarRGBA:") == 0)
2895 barRgba = getRGBA();
2896 // Get the RGBA for the background
2897 else if(strcmp(ptr, "BackgroundRGBA:") == 0)
2898 bkgRgba = getRGBA();
2899 // get the range
2900 else if(strcmp(ptr, "Range:") == 0)
2901 range = getInt();
2902 // get the step inc
2903 else if(strcmp(ptr, "Step:") == 0)
2904 step = getInt();
2905 // Get the Pen.
2906 else if(strcmp(ptr, "Pen:") == 0)
2907 idPen = getInt();
2908 // Get the Text
2909 else if (strcmp(ptr, "Text:") == 0)
2910 idText = getInt();
2914 // Create the control
2915 CProgressBar *ctrl = new CProgressBar(idCtrl, x, y, xPixel, yPixel, w, h, wPixel, hPixel, range);
2917 if(ctrl)
2919 ctrl->origin(origin);
2920 ctrl->hotSpot(hs);
2921 ctrl->ref(_X_Display, _Y_Display, _W_Display, _H_Display);
2923 ctrl->setStep( step );
2924 ctrl->setBackgroundColor( bkgRgba );
2925 ctrl->setBackgroundTexture( bkgTexture );
2926 ctrl->setProgressBarColor( barRgba );
2927 ctrl->setProgressBarTexture( barTexture );
2929 CPen pen = CInterfMngr::getPen(idPen);
2930 ctrl->shadow( pen.shadow() );
2931 ctrl->fontSize( pen.fontSize() );
2932 ctrl->color( pen.color() );
2933 if (idText !=0)
2934 ctrl->setText( CInterfMngr::getText(idText).toString() );
2936 if(idParent != 0)
2938 CControl *parent = CInterfMngr::getCtrl(idParent);
2939 if(parent)
2941 parent->addChild(ctrl);
2942 ctrl->parent(parent);
2946 addChild(idCtrl, ctrl);
2948 }// getProgressBar //
2953 //-----------------------------------------------
2954 // getCastingBar :
2955 //-----------------------------------------------
2956 void COSD::getCastingBar(uint idCtrl)
2958 uint bkgTexture = 0;
2959 uint barTexture = 0;
2960 uint idPen = 0;
2961 uint idText = 0;
2964 uint32 range = 100;
2965 uint32 step = 0;
2967 CRGBA bkgRgba(255,255,255,255);
2968 CRGBA barRgba(255,255,255,255);
2970 // Lecture de la partie commune du script de control.
2971 CONTROL_SCRIPT_MACRO
2973 // Get the Texture for the progress bar
2974 else if(strcmp(ptr, "BarTexture:") == 0)
2975 barTexture = getInt();
2976 // Get the Texture for the background
2977 else if(strcmp(ptr, "BackgroundTexture:") == 0)
2978 bkgTexture = getInt();
2979 // Get the RGBA for the progress bar
2980 else if(strcmp(ptr, "BarRGBA:") == 0)
2981 barRgba = getRGBA();
2982 // Get the RGBA for the background
2983 else if(strcmp(ptr, "BackgroundRGBA:") == 0)
2984 bkgRgba = getRGBA();
2985 // get the range
2986 else if(strcmp(ptr, "Range:") == 0)
2987 range = getInt();
2988 // get the step inc
2989 else if(strcmp(ptr, "Step:") == 0)
2990 step = getInt();
2991 // Get the Pen.
2992 else if(strcmp(ptr, "Pen:") == 0)
2993 idPen = getInt();
2994 // Get the Text
2995 else if (strcmp(ptr, "Text:") == 0)
2996 idText = getInt();
3000 // Create the control
3001 CCastingBar *ctrl = new CCastingBar(idCtrl, x, y, xPixel, yPixel, w, h, wPixel, hPixel, range);
3003 if(ctrl)
3005 ctrl->origin(origin);
3006 ctrl->hotSpot(hs);
3007 ctrl->ref(_X_Display, _Y_Display, _W_Display, _H_Display);
3009 ctrl->setStep( step );
3010 ctrl->setBackgroundColor( bkgRgba );
3011 ctrl->setBackgroundTexture( bkgTexture );
3012 ctrl->setProgressBarColor( barRgba );
3013 ctrl->setProgressBarTexture( barTexture );
3015 CPen pen = CInterfMngr::getPen(idPen);
3016 ctrl->shadow( pen.shadow() );
3017 ctrl->fontSize( pen.fontSize() );
3018 ctrl->color( pen.color() );
3019 if (idText !=0)
3020 ctrl->setText( CInterfMngr::getText(idText).toString() );
3022 if(idParent != 0)
3024 CControl *parent = CInterfMngr::getCtrl(idParent);
3025 if(parent)
3027 parent->addChild(ctrl);
3028 ctrl->parent(parent);
3032 addChild(idCtrl, ctrl);
3034 }// getCastingBar //
3038 //-----------------------------------------------
3039 // getBrickControl :
3041 //-----------------------------------------------
3042 void COSD::getBrickControl(uint idCtrl)
3044 uint idtexture = 0;
3045 bool tiled = false;
3046 CRGBA rgba;
3047 uint idText = 0;
3048 uint leftFunc = 0;
3049 uint rightFunc = 0;
3051 // Lecture de la partie commune du script de control.
3052 CONTROL_SCRIPT_MACRO
3054 // Get the Texture.
3055 else if(strcmp(ptr, "Texture:") == 0)
3056 idtexture = getInt();
3057 // Get the RGBA.
3058 else if(strcmp(ptr, "RGBA:") == 0)
3059 rgba = getRGBA();
3061 /* // Get the function to execute on left click
3062 else if(strcmp(ptr, "LeftClickFunction:") == 0)
3063 leftFunc = getInt();
3064 // Get the function to execute on left click
3065 else if(strcmp(ptr, "RightClickFunction:") == 0)
3066 rightFunc = getInt();
3068 // tiled or stretched
3069 else if(strcmp(ptr, "Tiled:") == 0)
3071 if (getInt() ==1)
3072 tiled = true;
3077 // Create the control.
3078 CBrickControl *brick = new CBrickControl(idCtrl, x, y, xPixel, yPixel, w, h, wPixel, hPixel, leftFunc, rightFunc);
3079 if(brick)
3081 brick->origin(origin);
3082 brick->hotSpot(hs);
3083 brick->ref(_X_Display, _Y_Display, _W_Display, _H_Display);
3085 if(idParent != 0)
3087 CControl *parent = CInterfMngr::getCtrl(idParent);
3088 if(parent)
3090 parent->addChild(brick);
3091 brick->parent(parent);
3097 addChild(idCtrl, brick);
3099 }// getBrickControl //
3105 //-----------------------------------------------
3106 // open :
3108 //-----------------------------------------------
3109 void COSD::open(ifstream &file)
3111 char tmpBuff[_MAX_LINE_SIZE];
3112 char delimiter[] = "[] \t";
3113 uint line = 0;
3115 // While it's not the end of the file.
3116 while(!file.eof())
3118 file.getline(tmpBuff, _MAX_LINE_SIZE);
3119 line++;
3121 char *key = strtok(tmpBuff, delimiter);
3123 // if the first char is a / then this is a comment line, skip it and go to next line
3124 if ((key != NULL) && (*key) != '/' )
3126 // Make the id.
3127 uint idCtrl = atoi(key);
3128 switch(CInterfMngr::getType(idCtrl))
3130 // The control is a Text.
3131 case CInterfMngr::CtrlText:
3132 getText(idCtrl);
3133 break;
3135 // The control is a Capture.
3136 case CInterfMngr::CtrlCapture:
3137 getCapture(idCtrl);
3138 break;
3140 // The control is a Button.
3141 case CInterfMngr::CtrlButton:
3142 getButton(idCtrl);
3143 break;
3145 // The control is a Radio Button.
3146 case CInterfMngr::CtrlRadioButton:
3147 getRadioButton(idCtrl);
3148 break;
3150 // The control is a Radio Controller
3151 case CInterfMngr::CtrlRadioController:
3152 getRadioController(idCtrl);
3153 break;
3155 // The control is a Bitmap.
3156 case CInterfMngr::CtrlBitmap:
3157 getBitmap(idCtrl);
3158 break;
3160 // The control is a List.
3161 case CInterfMngr::CtrlList:
3162 getList(idCtrl);
3163 break;
3165 // The control is a MultiList.
3166 case CInterfMngr::CtrlMultiList:
3167 getMultiList(idCtrl);
3168 break;
3170 // The control is a ChatBox.
3171 case CInterfMngr::CtrlChat:
3172 getChatBox(idCtrl);
3173 break;
3175 // The control is a ChatInput.
3176 case CInterfMngr::CtrlChatInput:
3177 getChatInput(idCtrl);
3178 break;
3180 // The control is a ChoiceList
3181 case CInterfMngr::CtrlChoiceList:
3182 getChoiceList(idCtrl);
3183 break;
3185 // The control is a CandidateList
3186 case CInterfMngr::CtrlCandidateList:
3187 getCandidateList(idCtrl);
3188 break;
3190 // The control is an HorizontalList
3191 case CInterfMngr::CtrlHorizontalList:
3192 getHorizontalList(idCtrl);
3193 break;
3195 // The control is an ControlList
3196 case CInterfMngr::CtrlControlList:
3197 getControlList(idCtrl);
3198 break;
3200 // The control is an SpellList
3201 case CInterfMngr::CtrlSpellList:
3202 getSpellList(idCtrl);
3203 break;
3205 // The control is an ProgressBar
3206 case CInterfMngr::CtrlProgressBar:
3207 getProgressBar(idCtrl);
3208 break;
3210 // The control is an CastingBar
3211 case CInterfMngr::CtrlCastingBar:
3212 getCastingBar(idCtrl);
3213 break;
3215 // The control is a brick control
3216 case CInterfMngr::CtrlBrick:
3217 getBrickControl(idCtrl);
3218 break;
3220 // The control is a Unknown.
3221 default:
3222 nlerror("Line %d : ID %d is undeclared in \"ctrls.txt\" OR the type is unknown !!", line, idCtrl);
3223 break;
3228 uint32 width, height;
3229 CInterfMngr::getWindowSize(width, height);
3230 resize(width, height);
3231 }// open //