1 /*
2  * Copyright 2011-2013 Arx Libertatis Team (see the AUTHORS file)
3  *
4  * This file is part of Arx Libertatis.
5  *
6  * Arx Libertatis is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Arx Libertatis is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Arx Libertatis.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 /* Based on:
20 ===========================================================================
21 ARX FATALIS GPL Source Code
22 Copyright (C) 1999-2010 Arkane Studios SA, a ZeniMax Media company.
23 
24 This file is part of the Arx Fatalis GPL Source Code ('Arx Fatalis Source Code').
25 
26 Arx Fatalis Source Code is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
27 License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
28 
29 Arx Fatalis Source Code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
30 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
31 
32 You should have received a copy of the GNU General Public License along with Arx Fatalis Source Code.  If not, see
33 <http://www.gnu.org/licenses/>.
34 
35 In addition, the Arx Fatalis Source Code is also subject to certain additional terms. You should have received a copy of these
36 additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Arx
37 Fatalis Source Code. If not, please request a copy in writing from Arkane Studios at the address below.
38 
39 If you have questions concerning this license or the applicable additional terms, you may contact in writing Arkane Studios, c/o
40 ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
41 ===========================================================================
42 */
43 
44 #include "gui/MenuWidgets.h"
45 
46 #include <cctype>
47 #include <cmath>
48 #include <cstring>
49 #include <cstdio>
50 #include <cstdlib>
51 #include <ctime>
52 #include <iomanip>
53 #include <iosfwd>
54 #include <limits>
55 #include <algorithm>
56 #include <sstream>
57 
58 #include <boost/foreach.hpp>
59 
60 #include "core/Application.h"
61 #include "core/Config.h"
62 #include "core/Core.h"
63 #include "core/GameTime.h"
64 #include "core/Localisation.h"
65 #include "core/SaveGame.h"
66 #include "core/Version.h"
67 
68 #include "gui/Menu.h"
69 #include "gui/MenuPublic.h"
70 #include "gui/Text.h"
71 #include "gui/Interface.h"
72 #include "gui/Credits.h"
73 #include "gui/TextManager.h"
74 
75 #include "graphics/Draw.h"
76 #include "graphics/Math.h"
77 #include "graphics/Renderer.h"
78 #include "graphics/data/TextureContainer.h"
79 #include "graphics/font/Font.h"
80 #include "graphics/texture/TextureStage.h"
81 
82 #include "input/Input.h"
83 
84 #include "scene/ChangeLevel.h"
85 #include "scene/GameSound.h"
86 #include "scene/LoadLevel.h"
87 
88 #include "window/RenderWindow.h"
89 
90 using std::wistringstream;
91 using std::min;
92 using std::max;
93 using std::string;
94 using std::vector;
95 
96 const std::string AUTO_RESOLUTION_STRING = "Automatic";
97 
98 static int newWidth;
99 static int newHeight;
100 static int newBpp;
101 static bool newFullscreen;
102 
103 #define NODEBUGZONE
104 
105 //-----------------------------------------------------------------------------
106 
107 #define RATIO_X(a)    (((float)a)*Xratio)
108 #define RATIO_Y(a)    (((float)a)*Yratio)
109 
110 
111 //-----------------------------------------------------------------------------
112 // Imported global variables and functions
113 extern ARX_MENU_DATA ARXmenu;
114 extern TextureContainer * scursor[];
115 extern long DANAESIZX;
116 extern long DANAESIZY;
117 
118 extern long REFUSE_GAME_RETURN;
119 
120 extern float PROGRESS_BAR_TOTAL;
121 extern float OLD_PROGRESS_BAR_COUNT;
122 extern float PROGRESS_BAR_COUNT;
123 
124 
125 float INTERFACE_RATIO(float a);
126 bool bNoMenu=false;
127 
128 void ARXMenu_Private_Options_Video_SetResolution(bool fullscreen, int _iWidth, int _iHeight, int _bpp);
129 
130 //-----------------------------------------------------------------------------
131 
132 static MenuCursor * pMenuCursor = NULL;
133 
134 static CWindowMenu *pWindowMenu=NULL;
135 CMenuState *pMenu;
136 
137 static CMenuElement * pMenuElementResume = NULL;
138 static CMenuElement * pMenuElementApply = NULL;
139 static CMenuElementText * pLoadConfirm = NULL;
140 CMenuElementText *pDeleteConfirm=NULL;
141 CMenuElementText *pDeleteButton=NULL;
142 CMenuCheckButton * fullscreenCheckbox = NULL;
143 static CMenuSliderText * pMenuSliderResol = NULL;
144 static CMenuSliderText * pMenuSliderBpp = NULL;
145 
146 float ARXTimeMenu;
147 float ARXOldTimeMenu;
148 float ARXDiffTimeMenu;
149 
150 bool bFade=false;
151 bool bFadeInOut=false;
152 int iFadeAction=-1;
153 float fFadeInOut=0.f;
154 
155 void ARX_MENU_Clicked_NEWQUEST();
156 
157 TextureContainer *pTextureLoad=NULL;
158 static TextureContainer *pTextureLoadRender=NULL;
159 
160 int iTimeToDrawD7=-3000;
161 
ARX_QuickSave()162 void ARX_QuickSave() {
163 
164 	if(REFUSE_GAME_RETURN) {
165 		return;
166 	}
167 
168 	ARX_SOUND_MixerPause(ARX_SOUND_MixerGame);
169 
170 	savegames.quicksave(savegame_thumbnail);
171 
172 	ARX_SOUND_MixerResume(ARX_SOUND_MixerGame);
173 }
174 
ARX_DrawAfterQuickLoad()175 void ARX_DrawAfterQuickLoad() {
176 
177 	iTimeToDrawD7 -= checked_range_cast<int>(FrameDiff);
178 
179 	float fColor;
180 
181 	if(iTimeToDrawD7>0)
182 	{
183 		fColor=1.f;
184 	}
185 	else
186 	{
187 		int iFade=-iTimeToDrawD7;
188 
189 		if(iFade>1000) return;
190 
191 		fColor=1.f-(((float)iFade)/1000.f);
192 	}
193 
194 	TextureContainer *pTex = TextureContainer::Load("graph/interface/icons/menu_main_save");
195 
196 	if(!pTex) return;
197 
198 	GRenderer->SetRenderState(Renderer::AlphaBlending, true);
199 	GRenderer->SetBlendFunc(Renderer::BlendOne, Renderer::BlendOne);
200 
201 	EERIEDrawBitmap2(0, 0, INTERFACE_RATIO_DWORD(pTex->m_dwWidth),
202 	                 INTERFACE_RATIO_DWORD(pTex->m_dwHeight), 0.f, pTex, Color::gray(fColor));
203 
204 	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
205 }
206 
ARX_QuickLoad()207 bool ARX_QuickLoad() {
208 
209 	SaveGameList::iterator save = savegames.quickload();
210 	if(save == savegames.end()) {
211 		// No saves found!
212 		return false;
213 	}
214 
215 	ARX_SOUND_MixerPause(ARX_SOUND_MixerGame);
216 
217 	LoadLevelScreen();
218 	PROGRESS_BAR_TOTAL = 238;
219 	OLD_PROGRESS_BAR_COUNT = PROGRESS_BAR_COUNT = 0;
220 	PROGRESS_BAR_COUNT += 1.f;
221 	LoadLevelScreen(save->level);
222 
223 	DanaeClearLevel();
224 
225 	ARX_CHANGELEVEL_Load(save->savefile);
226 
227 	REFUSE_GAME_RETURN = 0;
228 	ARX_SOUND_MixerResume(ARX_SOUND_MixerGame);
229 
230 	return true;
231 }
232 
233 //-----------------------------------------------------------------------------
234 
MENU_NoActiveWindow()235 bool MENU_NoActiveWindow()
236 {
237 	if( (!pWindowMenu)||
238 		((pWindowMenu)&&
239 		(pWindowMenu->eCurrentMenuState==MAIN)) ) return true;
240 
241 	return false;
242 }
243 
FontRenderText(Font * _pFont,Vec3f pos,const std::string & _pText,Color _c)244 void FontRenderText(Font* _pFont, Vec3f pos, const std::string& _pText, Color _c) {
245 	if(pTextManage) {
246 		long x = checked_range_cast<long>(pos.x);
247 		long y = checked_range_cast<long>(pos.y);
248 		pTextManage->AddText(_pFont, _pText, x, y, _c);
249 	}
250 }
251 
Check_Apply()252 void Check_Apply()
253 {
254 	if(pMenuElementApply)
255 	{
256 		if((config.video.resolution.x != newWidth) ||
257 		   (config.video.resolution.y != newHeight) ||
258 		   (config.video.fullscreen != newFullscreen) ||
259 		   (config.video.bpp!=newBpp)) {
260 			pMenuElementApply->SetCheckOn();
261 			((CMenuElementText*)pMenuElementApply)->lColor=((CMenuElementText*)pMenuElementApply)->lOldColor;
262 		}
263 		else
264 		{
265 			if(((CMenuElementText*)pMenuElementApply)->lColor!=Color(127,127,127))
266 			{
267 				pMenuElementApply->SetCheckOff();
268 				((CMenuElementText*)pMenuElementApply)->lOldColor=((CMenuElementText*)pMenuElementApply)->lColor;
269 				((CMenuElementText*)pMenuElementApply)->lColor=Color(127,127,127);
270 			}
271 		}
272 	}
273 }
274 
275 //-----------------------------------------------------------------------------
276 
FadeInOut(float _fVal)277 static void FadeInOut(float _fVal)
278 {
279 	TexturedVertex d3dvertex[4];
280 
281 	u32 iColor = Color::gray(_fVal).toBGR();
282 	d3dvertex[0].p.x=0;
283 	d3dvertex[0].p.y=0;
284 	d3dvertex[0].p.z=0.f;
285 	d3dvertex[0].rhw=0.999999f;
286 	d3dvertex[0].color=iColor;
287 
288 	d3dvertex[1].p.x=static_cast<float>(DANAESIZX);
289 	d3dvertex[1].p.y=0;
290 	d3dvertex[1].p.z=0.f;
291 	d3dvertex[1].rhw=0.999999f;
292 	d3dvertex[1].color=iColor;
293 
294 	d3dvertex[2].p.x=0;
295 	d3dvertex[2].p.y=static_cast<float>(DANAESIZY);
296 	d3dvertex[2].p.z=0.f;
297 	d3dvertex[2].rhw=0.999999f;
298 	d3dvertex[2].color=iColor;
299 
300 	d3dvertex[3].p.x=static_cast<float>(DANAESIZX);
301 	d3dvertex[3].p.y=static_cast<float>(DANAESIZY);
302 	d3dvertex[3].p.z=0.f;
303 	d3dvertex[3].rhw=0.999999f;
304 	d3dvertex[3].color=iColor;
305 
306 	GRenderer->ResetTexture(0);
307 	GRenderer->SetRenderState(Renderer::AlphaBlending, true);
308 
309 	GRenderer->SetBlendFunc(Renderer::BlendZero, Renderer::BlendInvSrcColor);
310 	GRenderer->SetRenderState(Renderer::DepthWrite, false);
311 	GRenderer->SetRenderState(Renderer::DepthTest, false);
312 	GRenderer->SetCulling(Renderer::CullNone);
313 
314 	EERIEDRAWPRIM(Renderer::TriangleStrip, d3dvertex, 4, true);
315 
316 	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
317 	GRenderer->SetRenderState(Renderer::DepthWrite, true);
318 
319 	GRenderer->SetRenderState(Renderer::DepthTest, true);
320 	GRenderer->SetCulling(Renderer::CullCCW);
321 }
322 
323 //-----------------------------------------------------------------------------
324 
ProcessFadeInOut(bool _bFadeIn,float _fspeed)325 bool ProcessFadeInOut(bool _bFadeIn,float _fspeed)
326 {
327 	FadeInOut(fFadeInOut);
328 
329 	if(!bFade) return true;
330 
331 	if(_bFadeIn)
332 	{
333 		fFadeInOut+=_fspeed*ARXDiffTimeMenu*( 1.0f / 100 );
334 
335 		if(fFadeInOut>1.f)
336 		{
337 			fFadeInOut=1.f;
338 			bFade=false;
339 		}
340 	}
341 	else
342 	{
343 		fFadeInOut-=_fspeed*ARXDiffTimeMenu*( 1.0f / 100 );
344 
345 		if(fFadeInOut<0.f)
346 		{
347 			fFadeInOut=0.f;
348 			bFade=false;
349 		}
350 	}
351 
352 	return false;
353 }
354 
355 //-----------------------------------------------------------------------------
356 
Menu2_Render()357 bool Menu2_Render() {
358 
359 	if(pMenuCursor == NULL)
360 		pMenuCursor = new MenuCursor();
361 
362 	pMenuCursor->Update();
363 
364 	ARXOldTimeMenu = ARXTimeMenu;
365 	ARXTimeMenu = arxtime.get_updated( false );
366 	ARXDiffTimeMenu = ARXTimeMenu-ARXOldTimeMenu;
367 
368 	// this means ArxTimeMenu is reset
369 	if(ARXDiffTimeMenu < 0) {
370 		ARXDiffTimeMenu = 0;
371 	}
372 
373 	GRenderer->GetTextureStage(0)->SetMinFilter(TextureStage::FilterLinear);
374 	GRenderer->GetTextureStage(0)->SetMagFilter(TextureStage::FilterLinear);
375 
376 	if(AMCM_NEWQUEST == ARXmenu.currentmode || AMCM_CREDITS == ARXmenu.currentmode) {
377 
378 		delete pWindowMenu, pWindowMenu = NULL;
379 		delete pMenu, pMenu = NULL;
380 
381 		if(ARXmenu.currentmode == AMCM_CREDITS){
382 			Credits::render();
383 			return true;
384 		}
385 
386 		return false;
387 	}
388 
389 	GRenderer->BeginScene();
390 
391 	if(pTextManage) {
392 		pTextManage->Clear();
393 	}
394 
395 	GRenderer->GetTextureStage(0)->SetWrapMode(TextureStage::WrapClamp);
396 
397 	GRenderer->SetRenderState(Renderer::Fog, false);
398 	GRenderer->SetRenderState(Renderer::DepthWrite, false);
399 	GRenderer->SetRenderState(Renderer::DepthTest, false);
400 	GRenderer->SetCulling(Renderer::CullNone);
401 
402 	MENUSTATE eOldMenuState=NOP;
403 	MENUSTATE eM;
404 
405 	if(!pMenu)
406 	{
407 		eM=NOP;
408 	}
409 	else
410 	{
411 		eM=pMenu->eOldMenuWindowState;
412 	}
413 
414 	Color lColor = Color(232, 204, 142);
415 
416 	if(    (!pMenu)|| ((pMenu)&&(pMenu->bReInitAll)) )
417 	{
418 		std::string szMenuText;
419 		bool bBOOL = false;
420 		CMenuElementText *me;
421 
422 		if(pMenu && pMenu->bReInitAll) {
423 			eOldMenuState = pMenu->eOldMenuState;
424 			delete pWindowMenu, pWindowMenu = NULL;
425 			delete pMenu, pMenu = NULL;
426 		}
427 
428 		pMenu = new CMenuState(MAIN);
429 		pMenu->eOldMenuWindowState=eM;
430 
431 		pMenu->pTexBackGround = TextureContainer::LoadUI("graph/interface/menus/menu_main_background", TextureContainer::NoColorKey);
432 
433 		int iPosMenuPrincipaleX = 370;
434 	int iPosMenuPrincipaleY=100;
435 	int iDecMenuPrincipaleY=50;
436 #define MACRO_MENU_PRINCIPALE(MACRO_button,MACRO_menu,MACRO_locate,MACRO_check){\
437 		szMenuText = getLocalised( MACRO_locate );\
438 		me = new CMenuElementText(MACRO_button, hFontMainMenu, szMenuText, RATIO_X(iPosMenuPrincipaleX), RATIO_Y(iPosMenuPrincipaleY), lColor, 1.8f, MACRO_menu);\
439 		if(MACRO_check)\
440 		{\
441 			pMenuElementResume=me;\
442 			ARXMenu_GetResumeGame(bBOOL);\
443 			if (bBOOL)\
444 			{\
445 				me->SetCheckOn();\
446 			}\
447 			else\
448 			{\
449 				me->SetCheckOff();\
450 				me->lColor=Color(127,127,127);\
451 			}\
452 		}\
453 		pMenu->AddMenuElement(me);\
454 		iPosMenuPrincipaleY+=iDecMenuPrincipaleY;\
455 	}
456 
457 	MACRO_MENU_PRINCIPALE(BUTTON_MENUMAIN_RESUMEGAME,RESUME_GAME,"system_menus_main_resumegame",1);
458 	MACRO_MENU_PRINCIPALE(BUTTON_MENUMAIN_NEWQUEST,NEW_QUEST,"system_menus_main_newquest",0);
459 	MACRO_MENU_PRINCIPALE(-1,EDIT_QUEST,"system_menus_main_editquest",0);
460 	MACRO_MENU_PRINCIPALE(BUTTON_MENUMAIN_OPTIONS,OPTIONS,"system_menus_main_options",0);
461 	MACRO_MENU_PRINCIPALE(BUTTON_MENUMAIN_CREDITS,CREDITS,"system_menus_main_credits",0);
462 	MACRO_MENU_PRINCIPALE(-1,QUIT,"system_menus_main_quit",0);
463 #undef MACRO_MENU_PRINCIPALE
464 		std::string version = arx_version;
465 		if(!arx_release_codename.empty()) {
466 			version += " \"";
467 			version += arx_release_codename;
468 			version += "\"";
469 		}
470 		float verPosX = RATIO_X(620) - hFontControls->getTextSize(version).x;
471 		me = new CMenuElementText( -1, hFontControls, version, verPosX, RATIO_Y(80), lColor, 1.0f, NOP );
472 
473 		me->SetCheckOff();
474 		me->lColor=Color(127,127,127);
475 		pMenu->AddMenuElement(me);
476 	}
477 
478 	bool bScroll=true;
479 	{
480 		if(pMenuElementResume)
481 		{
482 			bool bTemp;
483 			ARXMenu_GetResumeGame(bTemp);
484 
485 			if(bTemp)
486 			{
487 				pMenuElementResume->SetCheckOn();
488 				((CMenuElementText*)pMenuElementResume)->lColor=lColor;
489 			}
490 			else
491 			{
492 				pMenuElementResume->SetCheckOff();
493 				((CMenuElementText*)pMenuElementResume)->lColor=Color(127,127,127);
494 			}
495 		}
496 
497 		MENUSTATE eMenuState = pMenu->Update(checked_range_cast<int>(ARXDiffTimeMenu));
498 
499 		if(eOldMenuState!=NOP)
500 		{
501 			eMenuState=eOldMenuState;
502 			bScroll=false;
503 		}
504 
505 		if( eMenuState == RESUME_GAME )
506 		{
507 			pTextManage->Clear();
508 			ARXmenu.currentmode = AMCM_OFF;
509 			pMenu->eMenuState = NOP;
510 			pMenu->pZoneClick = NULL;
511 
512 			delete pWindowMenu, pWindowMenu = NULL;
513 			delete pMenu, pMenu = NULL;
514 
515 			GRenderer->SetRenderState(Renderer::AlphaBlending, false);
516 			GRenderer->GetTextureStage(0)->SetWrapMode(TextureStage::WrapRepeat);
517 			GRenderer->SetRenderState(Renderer::DepthWrite, true);
518 			GRenderer->SetRenderState(Renderer::DepthTest, true);
519 			GRenderer->EndScene();
520 
521 			return true;
522 		}
523 		else if (eMenuState!=NOP )
524 		{
525 			pMenu->eOldMenuState=eMenuState;
526 
527 			delete pWindowMenu, pWindowMenu = NULL;
528 
529 			//suivant la resolution
530 			int iWindowMenuWidth=(321);
531 			int iWindowMenuHeight=(430);
532 			int iWindowMenuPosX=(20);
533 			int iWindowMenuPosY=(480-iWindowMenuHeight)>>1;
534 			int    iWindowConsoleOffsetX=(0);
535 			int    iWindowConsoleOffsetY=(14-10);
536 			int    iWindowConsoleWidth=(iWindowMenuWidth-iWindowConsoleOffsetX);
537 			int    iWindowConsoleHeight=(iWindowMenuHeight-iWindowConsoleOffsetY+20);
538 			///////////////////////
539 
540 			float fPosX1 = RATIO_X(20);
541 			float fPosX2 = RATIO_X(200);
542 
543 			int iPosX2 = checked_range_cast<int>(fPosX2);
544 
545 			float fPosBack      = RATIO_X(10);
546 			float fPosBackY      = RATIO_Y(190);
547 			float fPosNext      = RATIO_X(140);
548 
549 			float fPosApply   = RATIO_X(240);
550 
551 			float fPosBDAY      = RATIO_Y(380);
552 
553 			pWindowMenu = new CWindowMenu(iWindowMenuPosX,iWindowMenuPosY,iWindowMenuWidth,iWindowMenuHeight,1);
554 
555 			switch(eMenuState)
556 			{
557 			//------------------ START NEW_QUEST
558 			case NEW_QUEST:
559 				{
560 					std::string szMenuText;
561 					bool bBOOL = false;
562 					ARXMenu_GetResumeGame(bBOOL);
563 
564 					if (!bBOOL)
565 					{
566 						break;
567 					}
568 
569 					CMenuElement *me = NULL;
570 					CWindowMenuConsole *pWindowMenuConsole=new CWindowMenuConsole(iWindowConsoleOffsetX,iWindowConsoleOffsetY,iWindowConsoleWidth,iWindowConsoleHeight,NEW_QUEST);
571 					szMenuText = getLocalised( "system_menus_main_editquest_confirm" );
572 					me=new CMenuElementText(-1, hFontMenu, szMenuText,0,0,lColor,1.f, NOP);
573 					me->bCheck = false;
574 					pWindowMenuConsole->AddMenuCenter(me);
575 
576 					szMenuText = getLocalised( "system_menus_main_newquest_confirm" );
577 					me=new CMenuElementText(-1, hFontMenu, szMenuText,0,0,lColor,1.f, NOP);
578 					me->bCheck = false;
579 					pWindowMenuConsole->AddMenuCenter(me);
580 
581 					CMenuPanel *pPanel = new CMenuPanel();
582 					szMenuText = getLocalised( "system_yes" );
583 					szMenuText += "   "; // TODO This space can probably go
584 					me = new CMenuElementText(BUTTON_MENUNEWQUEST_CONFIRM, hFontMenu, szMenuText, 0, 0,lColor,1.f, NEW_QUEST_ENTER_GAME);
585 					me->SetPos(RATIO_X(iWindowConsoleWidth - (me->GetWidth() + 10)),0);
586 					pPanel->AddElementNoCenterIn(me);
587 					szMenuText = getLocalised( "system_no" );
588 					me = new CMenuElementText(-1, hFontMenu, szMenuText, fPosBack, 0,lColor,1.f, MAIN);
589 					me->SetShortCut(Keyboard::Key_Escape);
590 					pPanel->AddElementNoCenterIn(me);
591 
592 					pPanel->Move(0, checked_range_cast<int>(fPosBDAY));
593 
594 					pWindowMenuConsole->AddMenu(pPanel);
595 					pWindowMenu->AddConsole(pWindowMenuConsole);
596 					pWindowMenu->eCurrentMenuState=NEW_QUEST;
597 
598 					}
599 				break;
600 			//------------------ END NEW_QUEST
601 			case EDIT_QUEST:
602 				{
603 					CMenuElement *me;
604 					CMenuElement *me01;
605 					CMenuPanel *pPanel;
606 					TextureContainer *pTex;
607 					std::string szMenuText;
608 					CWindowMenuConsole *pWindowMenuConsole=new CWindowMenuConsole(iWindowConsoleOffsetX,iWindowConsoleOffsetY,iWindowConsoleWidth,iWindowConsoleHeight,EDIT_QUEST);
609 
610 					szMenuText = getLocalised( "system_menus_main_editquest_load");
611 					me = new CMenuElementText(BUTTON_MENUEDITQUEST_LOAD_INIT, hFontMenu, szMenuText, 0, 0, lColor, 1.f, EDIT_QUEST_LOAD);
612 					me->lData = -1;
613 					pWindowMenuConsole->AddMenuCenter(me);
614 
615 					szMenuText = getLocalised( "system_menus_main_editquest_save");
616 					me = new CMenuElementText(-1, hFontMenu, szMenuText, 0, 0, lColor, 1.f, EDIT_QUEST_SAVE);
617 					bool bBOOL;
618 					ARXMenu_GetResumeGame(bBOOL);
619 
620 					if (!bBOOL)
621 					{
622 						me->SetCheckOff();
623 						((CMenuElementText*)me)->lColor=Color(127,127,127);
624 					}
625 
626 					pWindowMenuConsole->AddMenuCenter(me);
627 
628 					pTex = TextureContainer::Load("graph/interface/menus/back");
629 					me = new CMenuCheckButton(-1, fPosBack, fPosBackY, pTex?pTex->m_dwWidth:0, pTex, NULL, NULL);
630 					me->eMenuState = MAIN;
631 					me->SetShortCut(Keyboard::Key_Escape);
632 					pWindowMenuConsole->AddMenu(me);
633 
634 					pWindowMenu->eCurrentMenuState = EDIT_QUEST;
635 					pWindowMenu->AddConsole(pWindowMenuConsole);
636 
637 					// LOAD ---------------------------------------------------
638 					pWindowMenuConsole=new CWindowMenuConsole(iWindowConsoleOffsetX,iWindowConsoleOffsetY-(40),iWindowConsoleWidth,iWindowConsoleHeight,EDIT_QUEST_LOAD);
639 					pWindowMenuConsole->lData = -1;
640 					pWindowMenuConsole->iInterligne = 5;
641 
642 					pTex = TextureContainer::Load("graph/interface/icons/menu_main_load");
643 					me = new CMenuCheckButton(-1, 0, 0, pTex?pTex->m_dwWidth:0, pTex, NULL, NULL);
644 					((CMenuCheckButton *)me)->bCheck = false;
645 					pWindowMenuConsole->AddMenuCenter(me);
646 
647 					string quicksaveName = getLocalised("system_menus_main_quickloadsave", "Quicksave");
648 
649 					// TODO make this list scrollable
650 					// TODO align the date part to the right!
651 
652 					{
653 
654 						size_t quicksaveNum = 0;
655 
656 						// Show quicksaves.
657 						for(size_t i = 0; i < savegames.size(); i++) {
658 							const SaveGame & save = savegames[i];
659 
660 							if(!save.quicksave) {
661 								continue;
662 							}
663 
664 							std::ostringstream text;
665 							text << quicksaveName << ' ' << ++quicksaveNum << "   " << save.time;
666 
667 							CMenuElement * e = new CMenuElementText(BUTTON_MENUEDITQUEST_LOAD, hFontControls,
668 							                                        text.str(), fPosX1, 0.f, lColor, .8f, NOP);
669 							e->lData = i;
670 							pWindowMenuConsole->AddMenuCenterY(e);
671 						}
672 
673 						// Show regular saves.
674 						for(size_t i = 0; i < savegames.size(); i++) {
675 							const SaveGame & save = savegames[i];
676 
677 							if(save.quicksave) {
678 								continue;
679 							}
680 
681 							string text = save.name +  "   " + save.time;
682 
683 							CMenuElement * e = new CMenuElementText(BUTTON_MENUEDITQUEST_LOAD, hFontControls,
684 							                                        text, fPosX1, 0.f, lColor, 0.8f, NOP);
685 							e->lData = i;
686 							pWindowMenuConsole->AddMenuCenterY(e);
687 						}
688 
689 						CMenuElement * confirm = new CMenuElementText(-1, hFontControls, " ", fPosX1, 0.f,
690 						                                              lColor, 0.8f, EDIT_QUEST_SAVE_CONFIRM);
691 						confirm->SetCheckOff();
692 						confirm->lData = -1;
693 						pWindowMenuConsole->AddMenuCenterY(confirm);
694 
695 						// Delete button
696 						szMenuText = getLocalised("system_menus_main_editquest_delete");
697 						szMenuText += "   ";
698 						me = new CMenuElementText(BUTTON_MENUEDITQUEST_DELETE_CONFIRM, hFontMenu, szMenuText, 0, 0,lColor,1.f, EDIT_QUEST_LOAD);
699 						me->SetPos(RATIO_X(iWindowConsoleWidth-10)-me->GetWidth(), RATIO_Y(42));
700 						pDeleteConfirm=(CMenuElementText*)me;
701 						me->SetCheckOff();
702 						((CMenuElementText*)me)->lOldColor = ((CMenuElementText*)me)->lColor;
703 						((CMenuElementText*)me)->lColor = Color::grayb(127);
704 						pWindowMenuConsole->AddMenu(me);
705 
706 						// Load button
707 						szMenuText = getLocalised("system_menus_main_editquest_load");
708 						szMenuText += "   ";
709 						me = new CMenuElementText(BUTTON_MENUEDITQUEST_LOAD_CONFIRM, hFontMenu, szMenuText, 0, 0,lColor,1.f, MAIN);
710 						me->SetPos(RATIO_X(iWindowConsoleWidth-10)-me->GetWidth(), fPosBDAY + RATIO_Y(40));
711 						pLoadConfirm=(CMenuElementText*)me;
712 						me->SetCheckOff();
713 						((CMenuElementText*)me)->lOldColor = ((CMenuElementText*)me)->lColor;
714 						((CMenuElementText*)me)->lColor = Color::grayb(127);
715 						pWindowMenuConsole->AddMenu(me);
716 
717 						// Back button
718 						CMenuPanel *pc = new CMenuPanel();
719 						pTex = TextureContainer::Load("graph/interface/menus/back");
720 						me = new CMenuCheckButton(-1, fPosBack, fPosBackY + RATIO_Y(20), pTex?pTex->m_dwWidth:0, pTex, NULL, NULL);
721 						me->eMenuState = EDIT_QUEST;
722 						me->SetShortCut(Keyboard::Key_Escape);
723 						pc->AddElementNoCenterIn(me);
724 						pWindowMenuConsole->AddMenu(pc);
725 					}
726 					pWindowMenu->AddConsole(pWindowMenuConsole);
727 
728 					// SAVE----------------------------------------------------
729 					pWindowMenuConsole=new CWindowMenuConsole(iWindowConsoleOffsetX,iWindowConsoleOffsetY - (40), iWindowConsoleWidth,iWindowConsoleHeight,EDIT_QUEST_SAVE);
730 					pWindowMenuConsole->iInterligne = 5;
731 
732 					pTex = TextureContainer::Load("graph/interface/icons/menu_main_save");
733 					me = new CMenuCheckButton(-1, fPosBack, 0, pTex?pTex->m_dwWidth:0, pTex, NULL, NULL);
734 					((CMenuCheckButton *)me)->bCheck = false;
735 					pWindowMenuConsole->AddMenuCenter(me);
736 
737 					size_t quicksaveNum = 0;
738 
739 					// Show quicksaves.
740 					for(size_t i = 0; i < savegames.size(); i++) {
741 						const SaveGame & save = savegames[i];
742 
743 						if(!save.quicksave) {
744 							continue;
745 						}
746 
747 						std::ostringstream text;
748 						text << quicksaveName << ' ' << ++quicksaveNum << "   " << save.time;
749 
750 						CMenuElement * e = new CMenuElementText(BUTTON_MENUEDITQUEST_SAVEINFO, hFontControls,
751 						                                        text.str(), fPosX1, 0.f, Color::grayb(127),
752 						                                        .8f, EDIT_QUEST_SAVE_CONFIRM);
753 						e->SetCheckOff();
754 						e->lData = i;
755 						pWindowMenuConsole->AddMenuCenterY(e);
756 					}
757 
758 					// Show regular saves.
759 					for(size_t i = 0; i < savegames.size(); i++) {
760 						const SaveGame & save = savegames[i];
761 
762 						if(save.quicksave) {
763 							continue;
764 						}
765 
766 						string text = save.name +  "   " + save.time;
767 
768 						CMenuElement * e = new CMenuElementText(BUTTON_MENUEDITQUEST_SAVEINFO, hFontControls,
769 						                                        text, fPosX1, 0.f, lColor, .8f,
770 						                                        EDIT_QUEST_SAVE_CONFIRM);
771 						e->lData = i;
772 						pWindowMenuConsole->AddMenuCenterY(e);
773 					}
774 
775 					for(size_t i = savegames.size(); i <= 15; i++) {
776 
777 						std::ostringstream text;
778 						text << '-' << std::setfill('0') << std::setw(4) << i << '-';
779 
780 						CMenuElementText * e = new CMenuElementText(BUTTON_MENUEDITQUEST_SAVEINFO, hFontControls, text.str(), fPosX1,
781 						                                            0.f, lColor, .8f,
782 						                                            EDIT_QUEST_SAVE_CONFIRM);
783 
784 						e->eMenuState = EDIT_QUEST_SAVE_CONFIRM;
785 						e->lData = -1;
786 						pWindowMenuConsole->AddMenuCenterY(e);
787 					}
788 
789 					me01 = new CMenuElementText(-1, hFontControls, " ", fPosX1, 0.f, lColor, 0.8f, EDIT_QUEST_SAVE_CONFIRM);
790 					me01->lData = -1;
791 					me01->SetCheckOff();
792 					pWindowMenuConsole->AddMenuCenterY((CMenuElementText*)me01);
793 
794 					pTex = TextureContainer::Load("graph/interface/menus/back");
795 					me = new CMenuCheckButton(-1, fPosBack, fPosBackY + RATIO_Y(20), pTex?pTex->m_dwWidth:0, pTex, NULL, NULL);
796 
797 					me->eMenuState = EDIT_QUEST;
798 					me->SetShortCut(Keyboard::Key_Escape);
799 					pWindowMenuConsole->AddMenu(me);
800 
801 					pWindowMenu->AddConsole(pWindowMenuConsole);
802 
803 					// SAVE CONFIRM--------------------------------------------
804 					pWindowMenuConsole = new CWindowMenuConsole(iWindowConsoleOffsetX,iWindowConsoleOffsetY,iWindowConsoleWidth,iWindowConsoleHeight,EDIT_QUEST_SAVE_CONFIRM);
805 					pWindowMenuConsole->lData = -1;
806 
807 					pTex = TextureContainer::Load("graph/interface/icons/menu_main_save");
808 					me = new CMenuCheckButton(-1, 0, 0, pTex?pTex->m_dwWidth:0, pTex, NULL, NULL);
809 					((CMenuCheckButton *)me)->bCheck = false;
810 					pWindowMenuConsole->AddMenuCenter(me);
811 
812 					szMenuText = getLocalised("system_menu_editquest_newsavegame", "---");
813 
814 					me = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, NOP);
815 					me->lData = -1;
816 
817 					pWindowMenuConsole->AddMenuCenter(me);
818 					me->eState=EDIT;
819 					me->ePlace=CENTER;
820 
821 					pPanel = new CMenuPanel();
822 
823 					// Delete button
824 					szMenuText = getLocalised("system_menus_main_editquest_delete");
825 					me = new CMenuElementText(BUTTON_MENUEDITQUEST_DELETE, hFontMenu, szMenuText, 0, 0,lColor,1.f, EDIT_QUEST_SAVE);
826 					me->SetPos(RATIO_X(iWindowConsoleWidth-10)-me->GetWidth(), RATIO_Y(5));
827 					pDeleteButton = (CMenuElementText*)me;
828 					((CMenuElementText*)me)->lOldColor = ((CMenuElementText*)me)->lColor;
829 					pPanel->AddElementNoCenterIn(me);
830 
831 					// Save button
832 					szMenuText = getLocalised("system_menus_main_editquest_save");
833 					me = new CMenuElementText(BUTTON_MENUEDITQUEST_SAVE, hFontMenu, szMenuText, 0, 0,lColor,1.f, MAIN);
834 					me->SetPos(RATIO_X(iWindowConsoleWidth-10)-me->GetWidth(), fPosBDAY);
835 					pPanel->AddElementNoCenterIn(me);
836 
837 					// Back button
838 					pTex = TextureContainer::Load("graph/interface/menus/back");
839 					me = new CMenuCheckButton(-1, fPosBack, fPosBackY, pTex?pTex->m_dwWidth:0, pTex, NULL, NULL);
840 					me->eMenuState = EDIT_QUEST_SAVE;
841 					me->SetShortCut(Keyboard::Key_Escape);
842 					pPanel->AddElementNoCenterIn(me);
843 
844 					pWindowMenuConsole->AddMenu(pPanel);
845 
846 					pWindowMenu->AddConsole(pWindowMenuConsole);
847 					}
848 				break;
849 			case OPTIONS:
850 				{
851 					std::string szMenuText;
852 					CMenuElement *me;
853 					CMenuPanel *pc;
854 					TextureContainer *pTex;
855 
856 					CWindowMenuConsole *pWindowMenuConsole=new CWindowMenuConsole(iWindowConsoleOffsetX,iWindowConsoleOffsetY,iWindowConsoleWidth,iWindowConsoleHeight,OPTIONS);
857 
858 					szMenuText = getLocalised("system_menus_options_video");
859 					me = new CMenuElementText(BUTTON_MENUOPTIONSVIDEO_INIT, hFontMenu, szMenuText, 0, 0,lColor,1.f,OPTIONS_VIDEO);
860 					pWindowMenuConsole->AddMenuCenter(me);
861 
862 					szMenuText = getLocalised("system_menus_options_audio");
863 					me = new CMenuElementText(-1, hFontMenu, szMenuText, 0, 0,lColor,1.f,OPTIONS_AUDIO);
864 					pWindowMenuConsole->AddMenuCenter(me);
865 
866 					szMenuText = getLocalised("system_menus_options_input");
867 					me = new CMenuElementText(-1, hFontMenu, szMenuText, 0, 0,lColor,1.f,OPTIONS_INPUT);
868 					pWindowMenuConsole->AddMenuCenter(me);
869 
870 					pTex = TextureContainer::Load("graph/interface/menus/back");
871 					me = new CMenuCheckButton(-1, fPosBack, fPosBackY, pTex?pTex->m_dwWidth:0, pTex, NULL, NULL);
872 					me->eMenuState = MAIN;
873 					me->SetShortCut(Keyboard::Key_Escape);
874 					pWindowMenuConsole->AddMenu(me);
875 
876 					pWindowMenu->AddConsole(pWindowMenuConsole);
877 				//------------------ END OPTIONS
878 
879 				//------------------ START VIDEO
880 					pWindowMenuConsole=new CWindowMenuConsole(iWindowConsoleOffsetX,iWindowConsoleOffsetY - (35),iWindowConsoleWidth,iWindowConsoleHeight, OPTIONS_VIDEO);
881 
882 
883 					// Renderer selection
884 					{
885 
886 						pc = new CMenuPanel();
887 						szMenuText = getLocalised("system_menus_options_video_renderer", "Renderer");
888 						szMenuText += "  ";
889 						me = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, NOP);
890 						me->SetCheckOff();
891 						pc->AddElement(me);
892 						CMenuSliderText * slider = new CMenuSliderText(BUTTON_MENUOPTIONSVIDEO_RENDERER, 0, 0);
893 
894 						slider->AddText(new CMenuElementText(-1, hFontMenu, "Auto-Select", 0, 0, lColor, 1.f, OPTIONS_VIDEO_RENDERER_AUTOMATIC));
895 						slider->iPos = slider->vText.size() - 1;
896 #ifdef ARX_HAVE_SDL
897 						slider->AddText(new CMenuElementText(-1, hFontMenu, "OpenGL", 0, 0, lColor, 1.f, OPTIONS_VIDEO_RENDERER_OPENGL));
898 						if(config.window.framework == "SDL") {
899 							slider->iPos = slider->vText.size() - 1;
900 						}
901 #endif
902 #ifdef ARX_HAVE_D3D9
903 						slider->AddText(new CMenuElementText(-1, hFontMenu, "D3D 9", 0, 0, lColor, 1.f, OPTIONS_VIDEO_RENDERER_D3D9));
904 						if(config.window.framework == "D3D9") {
905 							slider->iPos = slider->vText.size() - 1;
906 						}
907 #endif
908 
909 						float fRatio    = (RATIO_X(iWindowConsoleWidth-9) - slider->GetWidth());
910 						slider->Move(checked_range_cast<int>(fRatio), 0);
911 						pc->AddElement(slider);
912 						pWindowMenuConsole->AddMenuCenterY(pc);
913 
914 					}
915 
916 
917 					szMenuText = getLocalised("system_menus_options_videos_full_screen");
918 					if(szMenuText.empty()) {
919 						// TODO once we ship our own amendmends to the loc files a cleaner
920 						// fix would be to just define system_menus_options_videos_full_screen
921 						// for the german version there
922 						szMenuText = getLocalised("system_menus_options_video_full_screen");
923 					}
924 					szMenuText += "  ";
925 					CMenuElementText * metemp = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, NOP);
926 					metemp->SetCheckOff();
927 					TextureContainer *pTex1 = TextureContainer::Load("graph/interface/menus/menu_checkbox_off");
928 					TextureContainer *pTex2 = TextureContainer::Load("graph/interface/menus/menu_checkbox_on");
929 					fullscreenCheckbox = new CMenuCheckButton(BUTTON_MENUOPTIONSVIDEO_FULLSCREEN, 0, 0, pTex1->m_dwWidth, pTex1, pTex2, metemp);
930 
931 					fullscreenCheckbox->iState= config.video.fullscreen ? 1 : 0;
932 
933 					pWindowMenuConsole->AddMenuCenterY(fullscreenCheckbox);
934 
935 					pc = new CMenuPanel();
936 					szMenuText = getLocalised("system_menus_options_video_resolution");
937 					szMenuText += "  ";
938 					me = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, NOP);
939 					me->SetCheckOff();
940 					pc->AddElement(me);
941 					pMenuSliderResol = new CMenuSliderText(BUTTON_MENUOPTIONSVIDEO_RESOLUTION, 0, 0);
942 
943 					pMenuSliderResol->setEnabled(config.video.fullscreen);
944 
945 					std::vector<unsigned> vBpp;
946 
947 					const RenderWindow::DisplayModes & modes = mainApp->GetWindow()->getDisplayModes();
948 					for(size_t i = 0; i != modes.size(); ++i) {
949 
950 						const RenderWindow::DisplayMode & mode = modes[i];
951 
952 						if(std::find(vBpp.begin(), vBpp.end(), mode.depth) == vBpp.end()) {
953 							vBpp.push_back(mode.depth);
954 						}
955 
956 						if(mode.depth != unsigned(config.video.bpp)) {
957 							continue;
958 						}
959 
960 						// find the aspect ratio
961 						unsigned a = mode.resolution.x;
962 						unsigned b = mode.resolution.y;
963 						while(b != 0) {
964 							unsigned t = a % b;
965 							a = b, b = t;
966 						}
967 						Vec2i aspect = mode.resolution / a;
968 
969 						std::stringstream ss;
970 						ss << mode.resolution.x << 'x' << mode.resolution.y;
971 
972 						if(aspect.x < 100 && aspect.y < 100) {
973 							if(aspect == Vec2i(8, 5)) {
974 								aspect = Vec2i(16, 10);
975 							}
976 							ss << " (" << aspect.x << ':' << aspect.y << ')';
977 						}
978 
979 						pMenuSliderResol->AddText(new CMenuElementText(-1, hFontMenu, ss.str(), 0, 0, lColor, 1.f, MENUSTATE(OPTIONS_VIDEO_RESOLUTION_0 + i)));
980 
981 						if(mode.resolution == config.video.resolution) {
982 							pMenuSliderResol->iPos = pMenuSliderResol->vText.size() - 1;
983 						}
984 					}
985 
986 					pMenuSliderResol->AddText(new CMenuElementText(-1, hFontMenu, AUTO_RESOLUTION_STRING, 0, 0, lColor, 1.f, MENUSTATE(OPTIONS_VIDEO_RESOLUTION_0 + modes.size())));
987 
988 					if(config.video.resolution == Vec2i::ZERO) {
989 						pMenuSliderResol->iPos = pMenuSliderResol->vText.size() - 1;
990 					}
991 
992 					float fRatio    = (RATIO_X(iWindowConsoleWidth-9) - pMenuSliderResol->GetWidth());
993 
994 					pMenuSliderResol->Move(checked_range_cast<int>(fRatio), 0);
995 
996 
997 					pc->AddElement(pMenuSliderResol);
998 
999 					pWindowMenuConsole->AddMenuCenterY(pc);
1000 
1001 					int iSize = me->GetWidth();
1002 					pc = new CMenuPanel();
1003 					szMenuText = getLocalised("system_menus_options_video_bpp");
1004 					szMenuText += " ";
1005 					me = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, NOP);
1006 					me->SetCheckOff();
1007 					pc->AddElement(me);
1008 					me = new CMenuSliderText(BUTTON_MENUOPTIONSVIDEO_BPP, 0, 0);
1009 					pMenuSliderBpp = (CMenuSliderText*)me;
1010 					pMenuSliderBpp->setEnabled(config.video.fullscreen);
1011 
1012 
1013 					std::sort(vBpp.begin(), vBpp.end());
1014 
1015 					std::vector<unsigned>::iterator ii;
1016 					for(ii=vBpp.begin();ii!=vBpp.end();++ii)
1017 					{
1018 						std::stringstream bpp;
1019 						bpp << *ii;
1020 						((CMenuSliderText*)me)->AddText(new CMenuElementText(-1, hFontMenu, bpp.str(), 0, 0, lColor, 1.f, (MENUSTATE)(BUTTON_MENUOPTIONSVIDEO_BPP)));
1021 
1022 						if(*ii == unsigned(config.video.bpp)) {
1023 							((CMenuSliderText*)me)->iPos = ((CMenuSliderText*)me)->vText.size()-1;
1024 						}
1025 					}
1026 
1027 					((CMenuSliderText *)me)->SetWidth(iSize);
1028 
1029 
1030 					fRatio    = (RATIO_X(iWindowConsoleWidth-9) - me->GetWidth());
1031 					me->Move(checked_range_cast<int>(fRatio), 0);
1032 
1033 
1034 					pc->AddElement(me);
1035 					pWindowMenuConsole->AddMenuCenterY(pc);
1036 
1037 					pc = new CMenuPanel();
1038 					szMenuText = getLocalised("system_menus_options_detail");
1039 					szMenuText += " ";
1040 					me = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, NOP);
1041 					me->SetCheckOff();
1042 					pc->AddElement(me);
1043 					me = new CMenuSliderText(BUTTON_MENUOPTIONSVIDEO_OTHERSDETAILS, 0, 0);
1044 					szMenuText = getLocalised("system_menus_options_video_texture_low");
1045 					((CMenuSliderText *)me)->AddText(new CMenuElementText(-1, hFontMenu, szMenuText, 0, 0,lColor,1.f, OPTIONS_OTHERDETAILS));
1046 					szMenuText = getLocalised("system_menus_options_video_texture_med");
1047 					((CMenuSliderText *)me)->AddText(new CMenuElementText(-1, hFontMenu, szMenuText, 0, 0,lColor,1.f, OPTIONS_OTHERDETAILS));
1048 					szMenuText = getLocalised("system_menus_options_video_texture_high");
1049 					((CMenuSliderText *)me)->AddText(new CMenuElementText(-1, hFontMenu, szMenuText, 0, 0,lColor,1.f, OPTIONS_OTHERDETAILS));
1050 
1051 
1052 					fRatio    = (RATIO_X(iWindowConsoleWidth-9) - me->GetWidth());
1053 					me->Move(checked_range_cast<int>(fRatio), 0);
1054 
1055 
1056 					pc->AddElement(me);
1057 					((CMenuSliderText *)me)->iPos = config.video.levelOfDetail;
1058 
1059 					pWindowMenuConsole->AddMenuCenterY(pc);
1060 
1061 					bool bBOOL = false;
1062 
1063 					pc = new CMenuPanel();
1064 					szMenuText = getLocalised("system_menus_options_video_brouillard");
1065 					me = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, NOP);
1066 					me->SetCheckOff();
1067 					pc->AddElement(me);
1068 					me = new CMenuSlider(BUTTON_MENUOPTIONSVIDEO_FOG, iPosX2, 0);
1069 					((CMenuSlider *)me)->setValue(config.video.fogDistance);
1070 					pc->AddElement(me);
1071 
1072 					pWindowMenuConsole->AddMenuCenterY(pc);
1073 
1074 					szMenuText = getLocalised("system_menus_options_video_crosshair", "Show Crosshair");
1075 					szMenuText += " ";
1076 					metemp = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, NOP);
1077 					metemp->SetCheckOff();
1078 					me = new CMenuCheckButton(BUTTON_MENUOPTIONSVIDEO_CROSSHAIR, 0, 0, pTex1->m_dwWidth, pTex1, pTex2, metemp);
1079 
1080 					((CMenuCheckButton*)me)->iState= config.video.showCrosshair ? 1 : 0;
1081 
1082 					pWindowMenuConsole->AddMenuCenterY(me);
1083 
1084 					szMenuText = getLocalised("system_menus_options_video_antialiasing", "antialiasing");
1085 					szMenuText += " ";
1086 					pTex1 = TextureContainer::Load("graph/interface/menus/menu_checkbox_off");
1087 					pTex2 = TextureContainer::Load("graph/interface/menus/menu_checkbox_on");
1088 					metemp = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, NOP);
1089 					metemp->SetCheckOff();
1090 					me = new CMenuCheckButton(BUTTON_MENUOPTIONSVIDEO_ANTIALIASING, 0, 0, pTex1->m_dwWidth, pTex1, pTex2, metemp);
1091 					((CMenuCheckButton*)me)->iState= config.video.antialiasing ? 1 : 0;
1092 					pWindowMenuConsole->AddMenuCenterY(me);
1093 					ARX_SetAntiAliasing();
1094 
1095 					szMenuText = getLocalised("system_menus_options_video_vsync", "VSync");
1096 					szMenuText += " ";
1097 					pTex1 = TextureContainer::Load("graph/interface/menus/menu_checkbox_off");
1098 					pTex2 = TextureContainer::Load("graph/interface/menus/menu_checkbox_on");
1099 					metemp = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, NOP);
1100 					metemp->SetCheckOff();
1101 					me = new CMenuCheckButton(BUTTON_MENUOPTIONSVIDEO_VSYNC, 0, 0, pTex1->m_dwWidth, pTex1, pTex2, metemp);
1102 					((CMenuCheckButton*)me)->iState= config.video.vsync ? 1 : 0;
1103 					pWindowMenuConsole->AddMenuCenterY(me);
1104 
1105 					pc = new CMenuPanel();
1106 					szMenuText = getLocalised("system_menus_video_apply");
1107 					szMenuText += "   ";
1108 					pMenuElementApply = me = new CMenuElementText(BUTTON_MENUOPTIONSVIDEO_APPLY, hFontMenu, szMenuText, fPosApply, 0.f, lColor, 1.f, NOP);
1109 					me->SetPos(RATIO_X(iWindowConsoleWidth-10)-me->GetWidth(), fPosBDAY + RATIO_Y(40));
1110 					me->SetCheckOff();
1111 					pc->AddElementNoCenterIn(me);
1112 
1113 					pTex = TextureContainer::Load("graph/interface/menus/back");
1114 					me = new CMenuCheckButton(BUTTON_MENUOPTIONSVIDEO_BACK, fPosBack, fPosBackY + RATIO_Y(20), pTex?pTex->m_dwWidth:0, pTex, NULL, NULL);
1115 					me->eMenuState = OPTIONS;
1116 					me->SetShortCut(Keyboard::Key_Escape);
1117 					pc->AddElementNoCenterIn(me);
1118 
1119 					pWindowMenuConsole->AddMenu(pc);
1120 
1121 					pWindowMenu->AddConsole(pWindowMenuConsole);
1122 					//------------------ END VIDEO
1123 
1124 					//------------------ START AUDIO
1125 					pWindowMenuConsole = new CWindowMenuConsole(iWindowConsoleOffsetX,iWindowConsoleOffsetY,iWindowConsoleWidth,iWindowConsoleHeight,OPTIONS_AUDIO);
1126 
1127 					// Audio backend selection
1128 					{
1129 
1130 						pc = new CMenuPanel();
1131 						szMenuText = getLocalised("system_menus_options_audio_backend", "Backend");
1132 						szMenuText += "  ";
1133 						me = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, NOP);
1134 						me->SetCheckOff();
1135 						pc->AddElement(me);
1136 						CMenuSliderText * slider = new CMenuSliderText(BUTTON_MENUOPTIONSAUDIO_BACKEND, 0, 0);
1137 
1138 						slider->AddText(new CMenuElementText(-1, hFontMenu, "Auto-Select", 0, 0, lColor, 1.f, OPTIONS_AUDIO_BACKEND_AUTOMATIC));
1139 						slider->iPos = slider->vText.size() - 1;
1140 #ifdef ARX_HAVE_OPENAL
1141 						slider->AddText(new CMenuElementText(-1, hFontMenu, "OpenAL", 0, 0, lColor, 1.f, OPTIONS_AUDIO_BACKEND_OPENAL));
1142 						if(config.audio.backend == "OpenAL") {
1143 							slider->iPos = slider->vText.size() - 1;
1144 						}
1145 #endif
1146 #ifdef ARX_HAVE_DSOUND
1147 						slider->AddText(new CMenuElementText(-1, hFontMenu, "Direct Sound", 0, 0, lColor, 1.f, OPTIONS_AUDIO_BACKEND_DSOUND));
1148 						if(config.audio.backend == "DirectSound") {
1149 							slider->iPos = slider->vText.size() - 1;
1150 						}
1151 #endif
1152 
1153 						float fRatio    = (RATIO_X(iWindowConsoleWidth-9) - slider->GetWidth());
1154 						slider->Move(checked_range_cast<int>(fRatio), 0);
1155 						pc->AddElement(slider);
1156 						pWindowMenuConsole->AddMenuCenterY(pc);
1157 
1158 					}
1159 
1160 					pc = new CMenuPanel();
1161 					szMenuText = getLocalised("system_menus_options_audio_master_volume");
1162 					me = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, OPTIONS_AUDIO_VOLUME);
1163 					me->SetCheckOff();
1164 					pc->AddElement(me);
1165 					me = new CMenuSlider(BUTTON_MENUOPTIONSAUDIO_MASTER, iPosX2, 0);
1166 					((CMenuSlider *)me)->setValue((int)config.audio.volume); // TODO use float sliders
1167 					pc->AddElement(me);
1168 					pWindowMenuConsole->AddMenuCenterY(pc);
1169 
1170 					pc = new CMenuPanel();
1171 					szMenuText = getLocalised("system_menus_options_audio_effects_volume");
1172 					me = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, OPTIONS_AUDIO);
1173 					me->SetCheckOff();
1174 					pc->AddElement(me);
1175 					me = new CMenuSlider(BUTTON_MENUOPTIONSAUDIO_SFX, iPosX2, 0);
1176 					((CMenuSlider *)me)->setValue((int)config.audio.sfxVolume);
1177 					pc->AddElement(me);
1178 					pWindowMenuConsole->AddMenuCenterY(pc);
1179 
1180 					pc = new CMenuPanel();
1181 					szMenuText = getLocalised("system_menus_options_audio_speech_volume");
1182 					me = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, OPTIONS_AUDIO);
1183 					me->SetCheckOff();
1184 					pc->AddElement(me);
1185 					me = new CMenuSlider(BUTTON_MENUOPTIONSAUDIO_SPEECH, iPosX2, 0);
1186 					((CMenuSlider *)me)->setValue((int)config.audio.speechVolume);
1187 					pc->AddElement(me);
1188 					pWindowMenuConsole->AddMenuCenterY(pc);
1189 
1190 					pc = new CMenuPanel();
1191 					szMenuText = getLocalised("system_menus_options_audio_ambiance_volume");
1192 					me = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, OPTIONS_AUDIO);
1193 					me->SetCheckOff();
1194 					pc->AddElement(me);
1195 					me = new CMenuSlider(BUTTON_MENUOPTIONSAUDIO_AMBIANCE, iPosX2, 0);
1196 					((CMenuSlider *)me)->setValue((int)config.audio.ambianceVolume);
1197 					pc->AddElement(me);
1198 					pWindowMenuConsole->AddMenuCenterY(pc);
1199 
1200 					szMenuText = getLocalised("system_menus_options_audio_eax", "EAX");
1201 					szMenuText += " ";
1202 					pTex1 = TextureContainer::Load("graph/interface/menus/menu_checkbox_off");
1203 					pTex2 = TextureContainer::Load("graph/interface/menus/menu_checkbox_on");
1204 					CMenuElementText * pElementText = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, OPTIONS_INPUT);
1205 					me = new CMenuCheckButton(BUTTON_MENUOPTIONSAUDIO_EAX, 0, 0, pTex1->m_dwWidth, pTex1, pTex2, pElementText);
1206 					((CMenuCheckButton*)me)->iState = config.audio.eax ? 1 : 0;
1207 
1208 					pWindowMenuConsole->AddMenuCenterY(me);
1209 
1210 					pTex = TextureContainer::Load("graph/interface/menus/back");
1211 					me = new CMenuCheckButton(-1, fPosBack, fPosBackY, pTex?pTex->m_dwWidth:0, pTex, NULL, NULL);
1212 					me->eMenuState = OPTIONS;
1213 					me->SetShortCut(Keyboard::Key_Escape);
1214 					pWindowMenuConsole->AddMenu(me);
1215 
1216 					pWindowMenu->AddConsole(pWindowMenuConsole);
1217 					//------------------ END AUDIO
1218 
1219 					//------------------ START INPUT
1220 					pWindowMenuConsole = new CWindowMenuConsole(iWindowConsoleOffsetX,iWindowConsoleOffsetY,iWindowConsoleWidth,iWindowConsoleHeight, OPTIONS_INPUT);
1221 
1222 					// Input backend selection
1223 					{
1224 
1225 						pc = new CMenuPanel();
1226 						szMenuText = getLocalised("system_menus_options_input_backend", "Backend");
1227 						szMenuText += "  ";
1228 						me = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, NOP);
1229 						me->SetCheckOff();
1230 						pc->AddElement(me);
1231 						CMenuSliderText * slider = new CMenuSliderText(BUTTON_MENUOPTIONS_CONTROLS_BACKEND, 0, 0);
1232 
1233 						slider->AddText(new CMenuElementText(-1, hFontMenu, "Auto-Select", 0, 0, lColor, 1.f, OPTIONS_INPUT_BACKEND_AUTOMATIC));
1234 						slider->iPos = slider->vText.size() - 1;
1235 #ifdef ARX_HAVE_SDL
1236 						slider->AddText(new CMenuElementText(-1, hFontMenu, "SDL", 0, 0, lColor, 1.f, OPTIONS_INPUT_BACKEND_SDL));
1237 						if(config.input.backend == "SDL") {
1238 							slider->iPos = slider->vText.size() - 1;
1239 						}
1240 #endif
1241 #ifdef ARX_HAVE_DINPUT8
1242 						slider->AddText(new CMenuElementText(-1, hFontMenu, "DInput 8", 0, 0, lColor, 1.f, OPTIONS_INPUT_BACKEND_DINPUT));
1243 						if(config.input.backend == "DirectInput8") {
1244 							slider->iPos = slider->vText.size() - 1;
1245 						}
1246 #endif
1247 
1248 						float fRatio    = (RATIO_X(iWindowConsoleWidth-9) - slider->GetWidth());
1249 						slider->Move(checked_range_cast<int>(fRatio), 0);
1250 						pc->AddElement(slider);
1251 						pWindowMenuConsole->AddMenuCenterY(pc);
1252 
1253 					}
1254 
1255 					szMenuText = getLocalised("system_menus_options_input_customize_controls");
1256 					me = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, OPTIONS_INPUT_CUSTOMIZE_KEYS_1);
1257 					pWindowMenuConsole->AddMenuCenterY(me);
1258 
1259 					szMenuText = getLocalised("system_menus_options_input_invert_mouse");
1260 					szMenuText += " ";
1261 					pTex1 = TextureContainer::Load("graph/interface/menus/menu_checkbox_off");
1262 					pTex2 = TextureContainer::Load("graph/interface/menus/menu_checkbox_on");
1263 					me = new CMenuCheckButton(BUTTON_MENUOPTIONS_CONTROLS_INVERTMOUSE, 0, 0, pTex1->m_dwWidth, pTex1, pTex2, new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, OPTIONS_INPUT));
1264 					bBOOL = false;
1265 					ARXMenu_Options_Control_GetInvertMouse(bBOOL);
1266 
1267 					if (bBOOL)
1268 					{
1269 						((CMenuCheckButton*)me)->iState=1;
1270 					}
1271 					else
1272 					{
1273 						((CMenuCheckButton*)me)->iState=0;
1274 					}
1275 
1276 					pWindowMenuConsole->AddMenuCenterY(me);
1277 
1278 					szMenuText = getLocalised("system_menus_options_auto_ready_weapon");
1279 					szMenuText += " ";
1280 					pTex1 = TextureContainer::Load("graph/interface/menus/menu_checkbox_off");
1281 					pTex2 = TextureContainer::Load("graph/interface/menus/menu_checkbox_on");
1282 					me = new CMenuCheckButton(BUTTON_MENUOPTIONS_CONTROLS_AUTOREADYWEAPON, 0, 0, pTex1->m_dwWidth, pTex1, pTex2, new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, OPTIONS_INPUT));
1283 
1284 					((CMenuCheckButton*)me)->iState = config.input.autoReadyWeapon ? 1 : 0;
1285 
1286 					pWindowMenuConsole->AddMenuCenterY(me);
1287 
1288 					szMenuText = getLocalised("system_menus_options_input_mouse_look_toggle");
1289 					szMenuText += " ";
1290 					pTex1 = TextureContainer::Load("graph/interface/menus/menu_checkbox_off");
1291 					pTex2 = TextureContainer::Load("graph/interface/menus/menu_checkbox_on");
1292 					me = new CMenuCheckButton(BUTTON_MENUOPTIONS_CONTROLS_MOUSELOOK, 0, 0, pTex1->m_dwWidth, pTex1, pTex2, new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, OPTIONS_INPUT));
1293 
1294 					((CMenuCheckButton*)me)->iState = config.input.mouseLookToggle ? 1 : 0;
1295 
1296 					pWindowMenuConsole->AddMenuCenterY(me);
1297 
1298 					pc = new CMenuPanel();
1299 					szMenuText = getLocalised("system_menus_options_input_mouse_sensitivity");
1300 					me = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, NOP);
1301 					me->SetCheckOff();
1302 					pc->AddElement(me);
1303 					me = new CMenuSlider(BUTTON_MENUOPTIONS_CONTROLS_MOUSESENSITIVITY, iPosX2, 0);
1304 					((CMenuSlider*)me)->setValue(config.input.mouseSensitivity);
1305 					pc->AddElement(me);
1306 					pWindowMenuConsole->AddMenuCenterY(pc);
1307 
1308 					szMenuText = getLocalised("system_menus_autodescription", "auto_description");
1309 					szMenuText += " ";
1310 					pTex1 = TextureContainer::Load("graph/interface/menus/menu_checkbox_off");
1311 					pTex2 = TextureContainer::Load("graph/interface/menus/menu_checkbox_on");
1312 					me = new CMenuCheckButton(BUTTON_MENUOPTIONS_CONTROLS_AUTODESCRIPTION, 0, 0, pTex1->m_dwWidth, pTex1, pTex2, new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, OPTIONS_INPUT));
1313 
1314 					((CMenuCheckButton*)me)->iState = config.input.autoDescription ? 1 : 0;
1315 
1316 					pWindowMenuConsole->AddMenuCenterY(me);
1317 
1318 					pc = new CMenuPanel();
1319 					szMenuText = getLocalised("system_menus_options_misc_quicksave_slots", "Quicksave slots");
1320 					me = new CMenuElementText(-1, hFontMenu, szMenuText, fPosX1, 0.f, lColor, 1.f, NOP);
1321 					me->SetCheckOff();
1322 					pc->AddElement(me);
1323 					me = new CMenuSlider(BUTTON_MENUOPTIONS_CONTROLS_QUICKSAVESLOTS, iPosX2, 0);
1324 					((CMenuSlider*)me)->setValue(config.misc.quicksaveSlots);
1325 					pc->AddElement(me);
1326 					pWindowMenuConsole->AddMenuCenterY(pc);
1327 
1328 					pTex = TextureContainer::Load("graph/interface/menus/back");
1329 					me = new CMenuCheckButton(-1, fPosBack, fPosBackY, pTex?pTex->m_dwWidth:0, pTex, NULL, NULL);
1330 					me->eMenuState = OPTIONS;
1331 					me->SetShortCut(Keyboard::Key_Escape);
1332 					pWindowMenuConsole->AddMenu(me);
1333 					pWindowMenu->AddConsole(pWindowMenuConsole);
1334 				//------------------ END INPUT
1335 
1336 				//------------------ START CUSTOM CONTROLS
1337 				char pNoDef1[]="---";
1338 				char pNoDef2[]="---";
1339 
1340 				#define CUSTOM_CTRL_X0    RATIO_X(20)
1341 				#define CUSTOM_CTRL_X1    RATIO_X(150)
1342 				#define CUSTOM_CTRL_X2    RATIO_X(245)
1343 					long fControlPosY    =    static_cast<long>(RATIO_Y(8.f));
1344 				#define CUSTOM_CTRL_FUNC(a,b,c,d){\
1345 						pc=new CMenuPanel();\
1346 						szMenuText = getLocalised(a, "?");\
1347 						me = new CMenuElementText(-1, hFontControls, szMenuText, CUSTOM_CTRL_X0, 0,lColor,.7f, NOP);\
1348 						me->SetCheckOff();\
1349 						pc->AddElement(me);\
1350 						me = new CMenuElementText(c, hFontControls, pNoDef1, CUSTOM_CTRL_X1, 0,lColor,.7f, NOP);\
1351 						me->eState=GETTOUCH;\
1352 						if((!b)||(c<0))\
1353 						{\
1354 							me->SetCheckOff();\
1355 							((CMenuElementText*)me)->lColor=Color(127,127,127);\
1356 						}\
1357 						pc->AddElement(me);\
1358 						me = new CMenuElementText(d, hFontControls, pNoDef2, CUSTOM_CTRL_X2, 0,lColor,.7f, NOP);\
1359 						me->eState=GETTOUCH;\
1360 						if(d<0)\
1361 						{\
1362 							me->SetCheckOff();\
1363 							((CMenuElementText*)me)->lColor=Color(127,127,127);\
1364 						}\
1365 						pc->AddElement(me);\
1366 						pc->Move(0,fControlPosY);\
1367 						pWindowMenuConsole->AddMenu(pc);\
1368 						fControlPosY += static_cast<long>( pc->GetHeight() + RATIO_Y(3.f) );\
1369 					};
1370 
1371 
1372 				#define CUSTOM_CTRL_FUNC2(a,b,c,d){\
1373 						pc=new CMenuPanel();\
1374 						szMenuText = getLocalised(a, "?");\
1375 						szMenuText += "2";\
1376 						me = new CMenuElementText(-1, hFontControls, szMenuText, CUSTOM_CTRL_X0, 0,lColor,.7f, NOP);\
1377 						me->SetCheckOff();\
1378 						pc->AddElement(me);\
1379 						me = new CMenuElementText(c, hFontControls, pNoDef1, CUSTOM_CTRL_X1, 0,lColor,.7f, NOP);\
1380 						me->eState=GETTOUCH;\
1381 						if((!b)||(c<0))\
1382 						{\
1383 							me->SetCheckOff();\
1384 							((CMenuElementText*)me)->lColor=Color(127,127,127);\
1385 						}\
1386 						pc->AddElement(me);\
1387 						me = new CMenuElementText(d, hFontControls, pNoDef2, CUSTOM_CTRL_X2, 0,lColor,.7f, NOP);\
1388 						me->eState=GETTOUCH;\
1389 						if(d<0)\
1390 						{\
1391 							me->SetCheckOff();\
1392 							((CMenuElementText*)me)->lColor=Color(127,127,127);\
1393 						}\
1394 						pc->AddElement(me);\
1395 						pc->Move(0,fControlPosY);\
1396 						pWindowMenuConsole->AddMenu(pc);\
1397 						fControlPosY += static_cast<long>( pc->GetHeight() + RATIO_Y(3.f) );\
1398 					};
1399 
1400 
1401 				#define CUSTOM_CTRL_FUNC3(a,default,b,c,d){\
1402 						pc=new CMenuPanel();\
1403 						szMenuText = getLocalised(a, default);\
1404 						me = new CMenuElementText(-1, hFontControls, szMenuText, CUSTOM_CTRL_X0, 0,lColor,.7f, NOP);\
1405 						me->SetCheckOff();\
1406 						pc->AddElement(me);\
1407 						me = new CMenuElementText(c, hFontControls, pNoDef1, CUSTOM_CTRL_X1, 0,lColor,.7f, NOP);\
1408 						me->eState=GETTOUCH;\
1409 						if((!b)||(c<0))\
1410 						{\
1411 							me->SetCheckOff();\
1412 							((CMenuElementText*)me)->lColor=Color(127,127,127);\
1413 						}\
1414 						pc->AddElement(me);\
1415 						me = new CMenuElementText(d, hFontControls, pNoDef2, CUSTOM_CTRL_X2, 0,lColor,.7f, NOP);\
1416 						me->eState=GETTOUCH;\
1417 						if(d<0)\
1418 						{\
1419 							me->SetCheckOff();\
1420 							((CMenuElementText*)me)->lColor=Color(127,127,127);\
1421 						}\
1422 						pc->AddElement(me);\
1423 						pc->Move(0,fControlPosY);\
1424 						pWindowMenuConsole->AddMenu(pc);\
1425 						fControlPosY += static_cast<long>( pc->GetHeight() + RATIO_Y(3.f) );\
1426 					};
1427 
1428 
1429 					pWindowMenuConsole=new CWindowMenuConsole(iWindowConsoleOffsetX,iWindowConsoleOffsetY,iWindowConsoleWidth,iWindowConsoleHeight,OPTIONS_INPUT_CUSTOMIZE_KEYS_1);
1430 
1431 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_mouselook",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_MOUSELOOK1, BUTTON_MENUOPTIONS_CONTROLS_CUST_MOUSELOOK2);
1432 
1433 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_action_combine",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_ACTIONCOMBINE1, BUTTON_MENUOPTIONS_CONTROLS_CUST_ACTIONCOMBINE2);
1434 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_jump",1,BUTTON_MENUOPTIONS_CONTROLS_CUST_JUMP1, BUTTON_MENUOPTIONS_CONTROLS_CUST_JUMP2);
1435 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_magic_mode",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_MAGICMODE1, BUTTON_MENUOPTIONS_CONTROLS_CUST_MAGICMODE2);
1436 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_stealth_mode",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_STEALTHMODE1, BUTTON_MENUOPTIONS_CONTROLS_CUST_STEALTHMODE2);
1437 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_walk_forward",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_WALKFORWARD1, BUTTON_MENUOPTIONS_CONTROLS_CUST_WALKFORWARD2);
1438 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_walk_backward",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_WALKBACKWARD1, BUTTON_MENUOPTIONS_CONTROLS_CUST_WALKBACKWARD2);
1439 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_strafe_left",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_STRAFELEFT1, BUTTON_MENUOPTIONS_CONTROLS_CUST_STRAFELEFT2);
1440 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_strafe_right",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_STRAFERIGHT1, BUTTON_MENUOPTIONS_CONTROLS_CUST_STRAFERIGHT2);
1441 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_lean_left",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_LEANLEFT1, BUTTON_MENUOPTIONS_CONTROLS_CUST_LEANLEFT2);
1442 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_lean_right",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_LEANRIGHT1, BUTTON_MENUOPTIONS_CONTROLS_CUST_LEANRIGHT2);
1443 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_crouch",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_CROUCH1, BUTTON_MENUOPTIONS_CONTROLS_CUST_CROUCH2);
1444 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_crouch_toggle",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_CROUCHTOGGLE1, BUTTON_MENUOPTIONS_CONTROLS_CUST_CROUCHTOGGLE2);
1445 
1446 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_strafe",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_STRAFE1, BUTTON_MENUOPTIONS_CONTROLS_CUST_STRAFE2);
1447 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_center_view",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_CENTERVIEW1, BUTTON_MENUOPTIONS_CONTROLS_CUST_CENTERVIEW2);
1448 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_freelook",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_FREELOOK1, BUTTON_MENUOPTIONS_CONTROLS_CUST_FREELOOK2);
1449 
1450 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_turn_left",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_TURNLEFT1, BUTTON_MENUOPTIONS_CONTROLS_CUST_TURNLEFT2);
1451 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_turn_right",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_TURNRIGHT1, BUTTON_MENUOPTIONS_CONTROLS_CUST_TURNRIGHT2);
1452 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_look_up",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_LOOKUP1, BUTTON_MENUOPTIONS_CONTROLS_CUST_LOOKUP2);
1453 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_look_down",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_LOOKDOWN1, BUTTON_MENUOPTIONS_CONTROLS_CUST_LOOKDOWN2);
1454 
1455 					pc=new CMenuPanel();
1456 
1457 					pTex = TextureContainer::Load("graph/interface/menus/back");
1458 					me = new CMenuCheckButton(BUTTON_MENUOPTIONS_CONTROLS_CUST_BACK, fPosBack, fPosBackY, pTex?pTex->m_dwWidth:0, pTex, NULL, NULL);
1459 					me->eMenuState = OPTIONS_INPUT;
1460 					me->SetShortCut(Keyboard::Key_Escape);
1461 					pc->AddElementNoCenterIn(me);
1462 					szMenuText = getLocalised( "system_menus_options_input_customize_default" );
1463 					me = new CMenuElementText(BUTTON_MENUOPTIONS_CONTROLS_CUST_DEFAULT, hFontMenu, szMenuText, 0, 0,lColor,1.f, NOP);
1464 					me->SetPos((RATIO_X(iWindowConsoleWidth) - me->GetWidth())*0.5f, fPosBDAY);
1465 					pc->AddElementNoCenterIn(me);
1466 					pTex = TextureContainer::Load("graph/interface/menus/next");
1467 					me = new CMenuCheckButton(BUTTON_MENUOPTIONS_CONTROLS_CUST_BACK, fPosNext, fPosBackY, pTex?pTex->m_dwWidth:0, pTex, NULL, NULL);
1468 					me->eMenuState = OPTIONS_INPUT_CUSTOMIZE_KEYS_2;
1469 					me->SetShortCut(Keyboard::Key_Escape);
1470 					pc->AddElementNoCenterIn(me);
1471 
1472 					pWindowMenuConsole->AddMenu(pc);
1473 
1474 					pWindowMenu->AddConsole(pWindowMenuConsole);
1475 					pWindowMenuConsole->ReInitActionKey();
1476 
1477 					pWindowMenuConsole=new CWindowMenuConsole(iWindowConsoleOffsetX,iWindowConsoleOffsetY,iWindowConsoleWidth,iWindowConsoleHeight,OPTIONS_INPUT_CUSTOMIZE_KEYS_2);
1478 
1479 					fControlPosY = static_cast<long>(RATIO_Y(8.f));
1480 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_inventory",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_INVENTORY1, BUTTON_MENUOPTIONS_CONTROLS_CUST_INVENTORY2);
1481 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_book",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOK1, BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOK2);
1482 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_bookcharsheet",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKCHARSHEET1, BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKCHARSHEET2);
1483 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_bookmap",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKMAP1, BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKMAP2);
1484 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_bookspell",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKSPELL1, BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKSPELL2);
1485 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_bookquest",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKQUEST1, BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKQUEST2);
1486 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_drink_potion_life",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_DRINKPOTIONLIFE1, BUTTON_MENUOPTIONS_CONTROLS_CUST_DRINKPOTIONLIFE2);
1487 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_drink_potion_mana",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_DRINKPOTIONMANA1, BUTTON_MENUOPTIONS_CONTROLS_CUST_DRINKPOTIONMANA2);
1488 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_torch",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_TORCH1, BUTTON_MENUOPTIONS_CONTROLS_CUST_TORCH2);
1489 
1490 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_cancelcurrentspell",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_CANCELCURSPELL1, BUTTON_MENUOPTIONS_CONTROLS_CUST_CANCELCURSPELL2);
1491 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_precast1",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_PRECAST1, BUTTON_MENUOPTIONS_CONTROLS_CUST_PRECAST1_2);
1492 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_precast2",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_PRECAST2, BUTTON_MENUOPTIONS_CONTROLS_CUST_PRECAST2_2);
1493 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_precast3",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_PRECAST3, BUTTON_MENUOPTIONS_CONTROLS_CUST_PRECAST3_2);
1494 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_weapon",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_WEAPON1, BUTTON_MENUOPTIONS_CONTROLS_CUST_WEAPON2);
1495 
1496 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_unequipweapon",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_UNEQUIPWEAPON1, BUTTON_MENUOPTIONS_CONTROLS_CUST_UNEQUIPWEAPON2);
1497 
1498 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_previous",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_PREVIOUS1, BUTTON_MENUOPTIONS_CONTROLS_CUST_PREVIOUS2);
1499 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_next",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_NEXT1, BUTTON_MENUOPTIONS_CONTROLS_CUST_NEXT2);
1500 
1501 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_quickload",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_QUICKLOAD, BUTTON_MENUOPTIONS_CONTROLS_CUST_QUICKLOAD2);
1502 					CUSTOM_CTRL_FUNC("system_menus_options_input_customize_controls_quicksave",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_QUICKSAVE, BUTTON_MENUOPTIONS_CONTROLS_CUST_QUICKSAVE2);
1503 
1504 					CUSTOM_CTRL_FUNC2("system_menus_options_input_customize_controls_bookmap",1, BUTTON_MENUOPTIONS_CONTROLS_CUST_MINIMAP1, BUTTON_MENUOPTIONS_CONTROLS_CUST_MINIMAP2);
1505 
1506 					CUSTOM_CTRL_FUNC3("system_menus_options_input_customize_controls_toggle_fullscreen", "Toggle fullscreen", 1,  BUTTON_MENUOPTIONS_CONTROLS_CUST_TOGGLE_FULLSCREEN1, BUTTON_MENUOPTIONS_CONTROLS_CUST_TOGGLE_FULLSCREEN2);
1507 
1508 					pc=new CMenuPanel();
1509 
1510 					pTex = TextureContainer::Load("graph/interface/menus/back");
1511 					me = new CMenuCheckButton(BUTTON_MENUOPTIONS_CONTROLS_CUST_BACK, fPosBack, fPosBackY, pTex?pTex->m_dwWidth:0, pTex, NULL, NULL);
1512 					me->eMenuState = OPTIONS_INPUT_CUSTOMIZE_KEYS_1;
1513 					me->SetShortCut(Keyboard::Key_Escape);
1514 					pc->AddElementNoCenterIn(me);
1515 					szMenuText = getLocalised( "system_menus_options_input_customize_default" );
1516 					me = new CMenuElementText(BUTTON_MENUOPTIONS_CONTROLS_CUST_DEFAULT, hFontMenu, szMenuText, 0, 0,lColor,1.f, NOP);
1517 					me->SetPos((RATIO_X(iWindowConsoleWidth) - me->GetWidth())*0.5f, fPosBDAY);
1518 					pc->AddElementNoCenterIn(me);
1519 
1520 					pWindowMenuConsole->AddMenu(pc);
1521 
1522 					pWindowMenu->AddConsole(pWindowMenuConsole);
1523 					pWindowMenuConsole->ReInitActionKey();
1524 					#undef CUSTOM_CTRL_X0
1525 					#undef CUSTOM_CTRL_X1
1526 					#undef CUSTOM_CTRL_X2
1527 					#undef CUSTOM_CTRL_FUNC
1528 					#undef CUSTOM_CTRL_FUNC2
1529 					#undef CUSTOM_CTRL_FUNC3
1530 				//------------------ END CUSTOM CONTROLS
1531 
1532 					pWindowMenu->eCurrentMenuState=OPTIONS;
1533 				}
1534 				break;
1535 
1536 			case QUIT:
1537 				{
1538 					std::string szMenuText;
1539 					CMenuElement *me = NULL;
1540 					CWindowMenuConsole *pWindowMenuConsole=new CWindowMenuConsole(iWindowConsoleOffsetX,iWindowConsoleOffsetY,iWindowConsoleWidth,iWindowConsoleHeight,QUIT);
1541 					szMenuText = getLocalised("system_menus_main_quit");
1542 					me=new CMenuElementText(-1, hFontMenu, szMenuText,0,0,lColor,1.f, NOP);
1543 					me->bCheck = false;
1544 					pWindowMenuConsole->AddMenuCenter(me);
1545 
1546 					szMenuText = getLocalised("system_menus_main_editquest_confirm");
1547 					me=new CMenuElementText(-1, hFontMenu, szMenuText,0,0,lColor,1.f, NOP);
1548 					me->bCheck = false;
1549 					pWindowMenuConsole->AddMenuCenter(me);
1550 
1551 					CMenuPanel *pPanel = new CMenuPanel();
1552 					szMenuText = getLocalised("system_yes");
1553 
1554 					me = new CMenuElementText(BUTTON_MENUMAIN_QUIT, hFontMenu, szMenuText, 0, 0,lColor,1.f, NEW_QUEST_ENTER_GAME);
1555 
1556 					me->SetPos(RATIO_X(iWindowConsoleWidth-10)-me->GetWidth(), 0);
1557 					pPanel->AddElementNoCenterIn(me);
1558 					szMenuText = getLocalised("system_no");
1559 					me = new CMenuElementText(-1, hFontMenu, szMenuText, fPosBack, 0,lColor,1.f, MAIN);
1560 					me->SetShortCut(Keyboard::Key_Escape);
1561 					pPanel->AddElementNoCenterIn(me);
1562 
1563 					pPanel->Move(0, checked_range_cast<int>(fPosBDAY));
1564 					pWindowMenuConsole->AddMenu(pPanel);
1565 					pWindowMenu->AddConsole(pWindowMenuConsole);
1566 					pWindowMenu->eCurrentMenuState=QUIT;
1567 
1568 				}
1569 				break;
1570 
1571 			default: break; // Unhandled menu state.
1572 			}
1573 
1574 		}
1575 	}
1576 	pMenu->Render();
1577 
1578 	if(pWindowMenu)
1579 	{
1580 		if(!bScroll)
1581 		{
1582 			pWindowMenu->fAngle=90.f;
1583 			pWindowMenu->eCurrentMenuState=pMenu->eOldMenuWindowState;
1584 		}
1585 
1586 		pWindowMenu->Update(ARXDiffTimeMenu);
1587 
1588 		if (pWindowMenu)
1589 		{
1590 			MENUSTATE eMS=pWindowMenu->Render();
1591 
1592 			if(eMS!=NOP)
1593 			{
1594 				pMenu->eOldMenuWindowState=eMS;
1595 			}
1596 		}
1597 
1598 		Check_Apply();
1599 	}
1600 
1601 	bNoMenu=false;
1602 
1603 	// If the menu needs to be reinitialized, then the text in the TextManager is probably using bad fonts that were deleted already
1604 	// Skip one update in this case
1605 	if(pTextManage && !pMenu->bReInitAll)
1606 	{
1607 		pTextManage->Update(ARXDiffTimeMenu);
1608 		pTextManage->Render();
1609 	}
1610 
1611 	GRenderer->GetTextureStage(0)->SetWrapMode(TextureStage::WrapClamp);
1612 
1613 	GRenderer->SetRenderState(Renderer::Fog, false);
1614 	GRenderer->SetRenderState(Renderer::DepthWrite, false);
1615 	GRenderer->SetRenderState(Renderer::DepthTest, false);
1616 	GRenderer->SetCulling(Renderer::CullNone);
1617 	pMenuCursor->DrawCursor();
1618 
1619 	if (pTextureLoadRender)
1620 	{
1621 		GRenderer->SetRenderState(Renderer::DepthTest, false);
1622 
1623 		int iOffsetX = 0;
1624 		int iOffsetY=0;
1625 
1626 		if ((DANAEMouse.y + INTERFACE_RATIO_DWORD(pTextureLoad->m_dwHeight)) > DANAESIZY)
1627 		{
1628 
1629 			float fOffestY    = iOffsetY - INTERFACE_RATIO_DWORD(pTextureLoad->m_dwHeight) ;
1630 			iOffsetY = checked_range_cast<int>(fOffestY);
1631 		}
1632 
1633 		EERIEDrawBitmap(static_cast<float>(DANAEMouse.x + iOffsetX),
1634 		                static_cast<float>(DANAEMouse.y + iOffsetY),
1635 		                (float)INTERFACE_RATIO_DWORD(pTextureLoad->m_dwWidth),
1636 		                (float)INTERFACE_RATIO_DWORD(pTextureLoad->m_dwHeight),
1637 		                0.001f, pTextureLoad, Color::white);
1638 
1639 		GRenderer->ResetTexture(0);
1640 		EERIEDraw2DRect(static_cast<float>(DANAEMouse.x + iOffsetX),
1641 		                static_cast<float>(DANAEMouse.y + iOffsetY),
1642 		                DANAEMouse.x + iOffsetX + (float)INTERFACE_RATIO_DWORD(pTextureLoad->m_dwWidth),
1643 		                DANAEMouse.y + iOffsetY + (float)INTERFACE_RATIO_DWORD(pTextureLoad->m_dwHeight),
1644 		                0.01f, Color::white);
1645 
1646 		pTextureLoadRender=NULL;
1647 	}
1648 
1649 	if(ProcessFadeInOut(bFadeInOut,0.1f))
1650 	{
1651 		switch(iFadeAction)
1652 		{
1653 		case AMCM_CREDITS:
1654 			ARX_MENU_Clicked_CREDITS();
1655 			iFadeAction=-1;
1656 			bFadeInOut=false;
1657 			bFade=true;
1658 			break;
1659 		case AMCM_NEWQUEST:
1660 			ARX_MENU_Clicked_NEWQUEST();
1661 			iFadeAction=-1;
1662 			bFadeInOut=false;
1663 			bFade=true;
1664 			CINEMASCOPE = 0;
1665 			break;
1666 		case AMCM_OFF:
1667 			ARX_MENU_Clicked_QUIT_GAME();
1668 			iFadeAction=-1;
1669 			bFadeInOut=false;
1670 			bFade=true;
1671 			break;
1672 		}
1673 	}
1674 
1675 	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
1676 	GRenderer->GetTextureStage(0)->SetMinFilter(TextureStage::FilterLinear);
1677 	GRenderer->GetTextureStage(0)->SetMagFilter(TextureStage::FilterLinear);
1678 	GRenderer->GetTextureStage(0)->SetWrapMode(TextureStage::WrapRepeat);
1679 
1680 	GRenderer->SetRenderState(Renderer::DepthWrite, true);
1681 
1682 	GRenderer->SetRenderState(Renderer::DepthTest, true);
1683 	GRenderer->SetCulling(Renderer::CullCCW);
1684 
1685 	GRenderer->EndScene();
1686 	return true;
1687 }
1688 
1689 //-----------------------------------------------------------------------------
1690 
CMenuElement(MENUSTATE _ms)1691 CMenuElement::CMenuElement(MENUSTATE _ms) : CMenuZone(), enabled(true)
1692 {
1693 	ePlace=NOCENTER;
1694 	eState=TNOP;
1695 	eMenuState=_ms;
1696 	iShortCut=-1;
1697 }
1698 
1699 //-----------------------------------------------------------------------------
1700 
~CMenuElement()1701 CMenuElement::~CMenuElement()
1702 {
1703 	if( this == pMenuElementApply )
1704 	{
1705 		pMenuElementApply = NULL;
1706 	}
1707 
1708 	if( this == pMenuElementResume )
1709 	{
1710 		pMenuElementResume = NULL;
1711 	}
1712 
1713 	if( this == pLoadConfirm )
1714 	{
1715 		pLoadConfirm = NULL;
1716 	}
1717 
1718 	if( this == pDeleteConfirm )
1719 	{
1720 		pDeleteConfirm = NULL;
1721 	}
1722 
1723 	if( this == pDeleteButton )
1724 	{
1725 		pDeleteButton = NULL;
1726 	}
1727 
1728 	if( this == pMenuSliderResol )
1729 	{
1730 		pMenuSliderResol = NULL;
1731 	}
1732 
1733 	if(this == fullscreenCheckbox) {
1734 		fullscreenCheckbox = NULL;
1735 	}
1736 
1737 	if( this == pMenuSliderBpp )
1738 	{
1739 		pMenuSliderBpp = NULL;
1740 	}
1741 }
1742 
1743 //-----------------------------------------------------------------------------
1744 
OnShortCut()1745 CMenuElement* CMenuElement::OnShortCut()
1746 {
1747 	if(iShortCut==-1) return NULL;
1748 
1749 	if( GInput->isKeyPressedNowUnPressed(iShortCut) )
1750 	{
1751 		return this;
1752 	}
1753 
1754 	return NULL;
1755 }
1756 
1757 //-----------------------------------------------------------------------------
1758 
CMenuElementText(int _iID,Font * _pFont,const std::string & _pText,float _fPosX,float _fPosY,Color _lColor,float _fSize,MENUSTATE _eMs)1759 CMenuElementText::CMenuElementText(int _iID, Font* _pFont, const std::string& _pText,float _fPosX,float _fPosY,Color _lColor,float _fSize,MENUSTATE _eMs) : CMenuElement(_eMs)
1760 {
1761 	iID = _iID;
1762 
1763 	pFont = _pFont;
1764 
1765 	if( !_pText.compare( "---") )
1766 	{
1767 		bTestYDouble=true;
1768 	}
1769 
1770 	lpszText= _pText;
1771 
1772 	Vec2i textSize = _pFont->getTextSize(_pText);
1773 	rZone.left = checked_range_cast<Rect::Num>(_fPosX);
1774 	rZone.top = checked_range_cast<Rect::Num>(_fPosY);
1775 	rZone.right  = rZone.left + textSize.x;
1776 	rZone.bottom = rZone.top + textSize.y;
1777 
1778 	lColor=_lColor;
1779 	lColorHighlight=lOldColor=Color(255, 255, 255);
1780 
1781 	fSize=_fSize;
1782 	pRef=this;
1783 
1784 	bSelected = false;
1785 
1786 	iPosCursor = _pText.length() + 1;
1787 }
1788 
1789 //-----------------------------------------------------------------------------
1790 
~CMenuElementText()1791 CMenuElementText::~CMenuElementText()
1792 {
1793 }
1794 
1795 //-----------------------------------------------------------------------------
1796 
SetText(const std::string & _pText)1797 void CMenuElementText::SetText( const std::string& _pText )
1798 {
1799 	lpszText = _pText;
1800 
1801 	Vec2i textSize = pFont->getTextSize(_pText);
1802 
1803 	rZone.right  = textSize.x + rZone.left;
1804 	rZone.bottom = textSize.y + rZone.top;
1805 }
1806 
1807 //-----------------------------------------------------------------------------
1808 
Update(int _iDTime)1809 void CMenuElementText::Update(int _iDTime) {
1810 	(void)_iDTime;
1811 }
1812 
1813 //-----------------------------------------------------------------------------
1814 
OnMouseDoubleClick(int _iMouseButton)1815 bool CMenuElementText::OnMouseDoubleClick(int _iMouseButton)
1816 {
1817 	switch(iID)
1818 	{
1819 	case BUTTON_MENUEDITQUEST_LOAD:
1820 		OnMouseClick(_iMouseButton);
1821 
1822 		if (pWindowMenu)
1823 		{
1824 			for (size_t i = 0 ; i < pWindowMenu->vWindowConsoleElement.size() ; i++)
1825 			{
1826 				CWindowMenuConsole *p = pWindowMenu->vWindowConsoleElement[i];
1827 
1828 				if ( p->eMenuState == EDIT_QUEST_LOAD )
1829 				{
1830 					for (size_t j = 0 ; j < p->MenuAllZone.vMenuZone.size() ; j++)
1831 					{
1832 						CMenuElement *pMenuElement = (CMenuElement*) ( (CMenuElement*)p->MenuAllZone.vMenuZone[j] )->GetZoneWithID( BUTTON_MENUEDITQUEST_LOAD_CONFIRM );
1833 
1834 						if( pMenuElement )
1835 						{
1836 							pMenuElement->OnMouseClick( _iMouseButton );
1837 						}
1838 					}
1839 				}
1840 			}
1841 		}
1842 
1843 		return true;
1844 	}
1845 
1846 	return false;
1847 }
1848 
1849 //-----------------------------------------------------------------------------
1850 // true: block les zones de checks
OnMouseClick(int _iMouseButton)1851 bool CMenuElementText::OnMouseClick(int _iMouseButton) {
1852 
1853 	if(!enabled) {
1854 		return false;
1855 	}
1856 
1857 	(void)_iMouseButton;
1858 
1859 	switch(eState)
1860 	{
1861 	case EDIT:
1862 		eState=EDIT_TIME;
1863 		return true;
1864 	case GETTOUCH:
1865 		eState=GETTOUCH_TIME;
1866 		lOldColor=lColorHighlight;
1867 		return true;
1868 	default: break;
1869 	}
1870 
1871 	if (iID != BUTTON_MENUMAIN_RESUMEGAME)
1872 	{
1873 		ARX_SOUND_PlayMenu(SND_MENU_CLICK);
1874 	}
1875 
1876 	switch (iID)
1877 	{
1878 	case -1:
1879 		{
1880 			return false;
1881 		}
1882 		break;
1883 	// MENUMAIN
1884 	case BUTTON_MENUMAIN_RESUMEGAME:
1885 		{
1886 			pTextManage->Clear();
1887 			ARXMenu_ResumeGame();
1888 			ARX_SOUND_PlayMenu(SND_MENU_CLICK);
1889 		}
1890 		break;
1891 	case BUTTON_MENUMAIN_NEWQUEST:
1892 		{
1893 			bool bBOOL = false;
1894 			ARXMenu_GetResumeGame(bBOOL);
1895 
1896 			if (!bBOOL)
1897 			{
1898 				ARXMenu_NewQuest();
1899 			}
1900 		}
1901 		break;
1902 	case BUTTON_MENUMAIN_LOADQUEST:
1903 		{
1904 		}break;
1905 	case BUTTON_MENUMAIN_SAVEQUEST:
1906 		{
1907 		}break;
1908 	case BUTTON_MENUMAIN_MULTIPLAYER:
1909 		{
1910 		}break;
1911 	case BUTTON_MENUMAIN_OPTIONS:
1912 		{
1913 		}break;
1914 	case BUTTON_MENUMAIN_CREDITS:
1915 		{
1916 			ARXMenu_Credits();
1917 		}
1918 		break;
1919 	case BUTTON_MENUMAIN_QUIT:
1920 		{
1921 			ARXMenu_Quit();
1922 		}
1923 		break;
1924 	case BUTTON_MENUNEWQUEST_CONFIRM:
1925 		{
1926 			ARXMenu_NewQuest();
1927 		}
1928 		break;
1929 		// MENULOADQUEST
1930 		case BUTTON_MENUOPTIONSVIDEO_INIT: {
1931 			newWidth = config.video.resolution.x;
1932 			newHeight = config.video.resolution.y;
1933 			newFullscreen = config.video.fullscreen;
1934 			newBpp = config.video.bpp;
1935 			break;
1936 		}
1937 	case BUTTON_MENUEDITQUEST_LOAD_INIT:
1938 		{
1939 			if ( pWindowMenu )
1940 				for (size_t i = 0 ; i < pWindowMenu->vWindowConsoleElement.size() ; i++)
1941 				{
1942 					CWindowMenuConsole * p = pWindowMenu->vWindowConsoleElement[i];
1943 
1944 					if(p->eMenuState == EDIT_QUEST_LOAD) {
1945 
1946 						p->lData = lData;
1947 
1948 						for (size_t j = 0 ; j < p->MenuAllZone.vMenuZone.size() ; j++)
1949 						{
1950 							CMenuZone *cz = p->MenuAllZone.vMenuZone[j];
1951 
1952 							if ( cz->iID == BUTTON_MENUEDITQUEST_LOAD )
1953 							{
1954 								( (CMenuElementText *)cz )->bSelected = false;
1955 							}
1956 						}
1957 					}
1958 				}
1959 		}
1960 		break;
1961 	case BUTTON_MENUEDITQUEST_LOAD:
1962 		{
1963 			if (pWindowMenu)
1964 			{
1965 			pLoadConfirm->SetCheckOn();
1966 			pLoadConfirm->lColor = pLoadConfirm->lOldColor;
1967 			pDeleteConfirm->SetCheckOn();
1968 			pDeleteConfirm->lColor = pDeleteConfirm->lOldColor;
1969 
1970 				for (size_t i = 0 ; i < pWindowMenu->vWindowConsoleElement.size() ; i++)
1971 			{
1972 				CWindowMenuConsole *p = pWindowMenu->vWindowConsoleElement[i];
1973 
1974 				if(p->eMenuState == EDIT_QUEST_LOAD) {
1975 
1976 					p->lData = lData;
1977 
1978 						for (size_t j = 0 ; j < p->MenuAllZone.vMenuZone.size(); j++)
1979 					{
1980 						CMenuZone *cz = p->MenuAllZone.vMenuZone[j];
1981 
1982 						if ( cz->iID == BUTTON_MENUEDITQUEST_LOAD )
1983 						{
1984 							( (CMenuElementText *)cz )->bSelected = false;
1985 						}
1986 					}
1987 
1988 					bSelected = true;
1989 
1990 					}
1991 				}
1992 			}
1993 			}
1994 		break;
1995 	case BUTTON_MENUEDITQUEST_LOAD_CONFIRM:
1996 		{
1997 			if (pWindowMenu)
1998 			{
1999 				for (size_t i = 0 ; i < pWindowMenu->vWindowConsoleElement.size() ; i++)
2000 			{
2001 				CWindowMenuConsole *p = pWindowMenu->vWindowConsoleElement[i];
2002 
2003 				if(p->eMenuState == EDIT_QUEST_LOAD) {
2004 
2005 					lData = p->lData;
2006 					if(lData != -1) {
2007 						eMenuState = MAIN;
2008 						GRenderer->Clear(Renderer::DepthBuffer);
2009 						ARXMenu_LoadQuest(lData);
2010 						bNoMenu=true;
2011 						if(pTextManage) {
2012 							pTextManage->Clear();
2013 						}
2014 						break;
2015 					}
2016 				}
2017 			}
2018 
2019 			pLoadConfirm->SetCheckOff();
2020 			pLoadConfirm->lColor = Color::grayb(127);
2021 			pDeleteConfirm->SetCheckOff();
2022 			pDeleteConfirm->lColor = Color::grayb(127);
2023 			}
2024 		}
2025 		break;
2026 	case BUTTON_MENUEDITQUEST_LOAD_CONFIRM_BACK:
2027 		pLoadConfirm->SetCheckOff();
2028 		pLoadConfirm->lColor = Color::grayb(127);
2029 		pDeleteConfirm->SetCheckOff();
2030 		pDeleteConfirm->lColor = Color::grayb(127);
2031 		break;
2032 	// MENUSAVEQUEST
2033 	case BUTTON_MENUEDITQUEST_SAVE:
2034 		{
2035 			if (pWindowMenu)
2036 				for (size_t i = 0 ; i < pWindowMenu->vWindowConsoleElement.size() ; i++)
2037 			{
2038 				CWindowMenuConsole *p = pWindowMenu->vWindowConsoleElement[i];
2039 
2040 				if(p->eMenuState == EDIT_QUEST_SAVE_CONFIRM) {
2041 
2042 					p->lData = lData;
2043 					CMenuElementText * me = (CMenuElementText *) p->MenuAllZone.vMenuZone[1];
2044 
2045 					if(me) {
2046 						eMenuState = MAIN;
2047 						ARXMenu_SaveQuest(me->lpszText, me->lData);
2048 						break;
2049 					}
2050 				}
2051 			}
2052 		}
2053 		break;
2054 
2055 		// Delete save from the load menu
2056 		case BUTTON_MENUEDITQUEST_DELETE_CONFIRM: {
2057 			if(pWindowMenu) {
2058 				for(size_t i = 0 ; i < pWindowMenu->vWindowConsoleElement.size(); i++) {
2059 					CWindowMenuConsole *p = pWindowMenu->vWindowConsoleElement[i];
2060 					if(p->eMenuState == EDIT_QUEST_LOAD) {
2061 						lData = p->lData;
2062 						if(lData != -1) {
2063 							eMenuState = EDIT_QUEST_LOAD;
2064 							pMenu->bReInitAll = true;
2065 							savegames.remove(lData);
2066 							break;
2067 						}
2068 					}
2069 				}
2070 			}
2071 			pLoadConfirm->SetCheckOff();
2072 			pLoadConfirm->lColor = Color::grayb(127);
2073 			pDeleteConfirm->SetCheckOff();
2074 			pDeleteConfirm->lColor = Color::grayb(127);
2075 			break;
2076 		}
2077 
2078 		// Delete save from the save menu
2079 		case BUTTON_MENUEDITQUEST_DELETE: {
2080 			if(pWindowMenu) {
2081 				for(size_t i = 0 ; i < pWindowMenu->vWindowConsoleElement.size(); i++) {
2082 					CWindowMenuConsole *p = pWindowMenu->vWindowConsoleElement[i];
2083 					if(p->eMenuState == EDIT_QUEST_SAVE_CONFIRM) {
2084 						p->lData = lData;
2085 						CMenuElementText * me = (CMenuElementText *) p->MenuAllZone.vMenuZone[1];
2086 						if(me) {
2087 							eMenuState = EDIT_QUEST_SAVE;
2088 							pMenu->bReInitAll = true;
2089 							savegames.remove(me->lData);
2090 							break;
2091 						}
2092 					}
2093 				}
2094 			}
2095 			break;
2096 		}
2097 
2098 		case BUTTON_MENUOPTIONSVIDEO_APPLY: {
2099 			if(newWidth != config.video.resolution.x || newHeight!=config.video.resolution.y
2100 			   || newFullscreen != config.video.fullscreen || newBpp != config.video.bpp) {
2101 				ARXMenu_Private_Options_Video_SetResolution(newFullscreen, newWidth, newHeight,
2102 				                                            newBpp);
2103 				pMenuSliderResol->iOldPos = -1;
2104 				pMenuSliderBpp->iOldPos = -1;
2105 				fullscreenCheckbox->iOldState = -1;
2106 			}
2107 			pMenu->bReInitAll=true;
2108 		}
2109 		break;
2110 
2111 	// MENUOPTIONS_CONTROLS
2112 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_JUMP1:
2113 		{
2114 		}break;
2115 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_JUMP2:
2116 		{
2117 		}break;
2118 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_MAGICMODE1:
2119 		{
2120 		}break;
2121 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_MAGICMODE2:
2122 		{
2123 		}break;
2124 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_STEALTHMODE1:
2125 		{
2126 		}break;
2127 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_STEALTHMODE2:
2128 		{
2129 		}break;
2130 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_WALKFORWARD1:
2131 		{
2132 		}break;
2133 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_WALKFORWARD2:
2134 		{
2135 		}break;
2136 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_WALKBACKWARD1:
2137 		{
2138 		}break;
2139 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_WALKBACKWARD2:
2140 		{
2141 		}break;
2142 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_STRAFELEFT1:
2143 		{
2144 		}break;
2145 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_STRAFELEFT2:
2146 		{
2147 		}break;
2148 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_STRAFERIGHT1:
2149 		{
2150 		}break;
2151 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_STRAFERIGHT2:
2152 		{
2153 		}break;
2154 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_LEANLEFT1:
2155 		{
2156 		}break;
2157 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_LEANLEFT2:
2158 		{
2159 		}break;
2160 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_LEANRIGHT1:
2161 		{
2162 		}break;
2163 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_LEANRIGHT2:
2164 		{
2165 		}break;
2166 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_CROUCH1:
2167 		{
2168 		}break;
2169 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_CROUCH2:
2170 		{
2171 		}break;
2172 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_MOUSELOOK1:
2173 		{
2174 		}break;
2175 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_ACTIONCOMBINE1:
2176 		{
2177 		}break;
2178 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_INVENTORY1:
2179 		{
2180 		}break;
2181 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_INVENTORY2:
2182 		{
2183 		}break;
2184 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOK1:
2185 		{
2186 		}break;
2187 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOK2:
2188 		{
2189 		}break;
2190 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_DRINKPOTIONLIFE1:
2191 		{
2192 		}break;
2193 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_DRINKPOTIONLIFE2:
2194 		{
2195 		}break;
2196 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_DRINKPOTIONMANA1:
2197 		{
2198 		}break;
2199 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_DRINKPOTIONMANA2:
2200 		{
2201 		}break;
2202 	case BUTTON_MENUOPTIONS_CONTROLS_CUST_DEFAULT:
2203 		{
2204 		}break;
2205 	case BUTTON_MENUOPTIONS_CONTROLS_BACK:
2206 		{
2207 			config.save();
2208 		}
2209 		break;
2210 	}
2211 
2212 	if(eMenuState == EDIT_QUEST_SAVE_CONFIRM) {
2213 
2214 		for (size_t i = 0 ; i < pWindowMenu->vWindowConsoleElement.size() ; i++)
2215 		{
2216 			CWindowMenuConsole *p = pWindowMenu->vWindowConsoleElement[i];
2217 
2218 			if ( p->eMenuState == eMenuState )
2219 			{
2220 				p->lData = lData;
2221 				CMenuElementText * me = (CMenuElementText *) p->MenuAllZone.vMenuZone[1];
2222 
2223 				if(me) {
2224 
2225 					me->lData = lData;
2226 
2227 					if(lData != -1) {
2228 						me->SetText(savegames[lData].name);
2229 						pDeleteButton->lColor = pDeleteButton->lOldColor;
2230 						pDeleteButton->SetCheckOn();
2231 					} else {
2232 						pDeleteButton->lColor = Color::grayb(127);
2233 						pDeleteButton->SetCheckOff();
2234 						me->SetText(getLocalised("system_menu_editquest_newsavegame"));
2235 					}
2236 
2237 					p->AlignElementCenter(me);
2238 				}
2239 			}
2240 		}
2241 	}
2242 
2243 	return false;
2244 }
2245 
2246 //-----------------------------------------------------------------------------
2247 // true: block les zones de checks
OnShortCut()2248 CMenuElement* CMenuElementText::OnShortCut()
2249 {
2250 	if(iShortCut==-1) return NULL;
2251 
2252 	if( GInput->isKeyPressedNowUnPressed(iShortCut) )
2253 	{
2254 		return this;
2255 	}
2256 
2257 	return NULL;
2258 }
2259 
2260 //-----------------------------------------------------------------------------
2261 
Render()2262 void CMenuElementText::Render()
2263 {
2264 	if(bNoMenu) return;
2265 
2266 	Vec3f ePos;
2267 	ePos.x = (float) rZone.left;
2268 	ePos.y = (float) rZone.top;
2269 	ePos.z = 1;
2270 
2271 	if(bSelected) {
2272 		FontRenderText(pFont, ePos, lpszText, lColorHighlight);
2273 	} else if(enabled) {
2274 		FontRenderText(pFont, ePos, lpszText, lColor);
2275 	} else {
2276 		FontRenderText(pFont, ePos, lpszText, Color::grayb(127));
2277 	}
2278 
2279 }
2280 
2281 //-----------------------------------------------------------------------------
2282 
RenderMouseOver()2283 void CMenuElementText::RenderMouseOver()
2284 {
2285 	if(bNoMenu) return;
2286 
2287 	pMenuCursor->SetMouseOver();
2288 
2289 	GRenderer->SetRenderState(Renderer::AlphaBlending, true);
2290 	GRenderer->SetBlendFunc(Renderer::BlendOne, Renderer::BlendOne);
2291 
2292 	Vec3f ePos;
2293 	ePos.x = (float)rZone.left;
2294 	ePos.y = (float)rZone.top;
2295 	ePos.z = 1;
2296 
2297 	FontRenderText(pFont, ePos, lpszText, lColorHighlight);
2298 
2299 	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
2300 
2301 	switch(iID) {
2302 
2303 		case BUTTON_MENUEDITQUEST_LOAD:
2304 		case BUTTON_MENUEDITQUEST_SAVEINFO: {
2305 
2306 			if(lData == -1) {
2307 				pTextureLoadRender = NULL;
2308 				break;
2309 			}
2310 
2311 			const res::path & image = savegames[lData].thumbnail;
2312 			if(!image.empty()) {
2313 				TextureContainer * t = TextureContainer::LoadUI(image, TextureContainer::NoColorKey);
2314 				if(t != pTextureLoad) {
2315 					delete pTextureLoad;
2316 					pTextureLoad = t;
2317 				}
2318 				pTextureLoadRender = pTextureLoad;
2319 			}
2320 
2321 			break;
2322 		}
2323 
2324 		default: {
2325 			pTextureLoadRender = NULL;
2326 			break;
2327 		}
2328 	}
2329 }
2330 
2331 //-----------------------------------------------------------------------------
2332 
GetTextSize() const2333 Vec2i CMenuElementText::GetTextSize() const
2334 {
2335 	return pFont->getTextSize(lpszText);
2336 }
2337 
2338 //-----------------------------------------------------------------------------
2339 
CMenuState(MENUSTATE _ms)2340 CMenuState::CMenuState(MENUSTATE _ms)
2341 {
2342 	bReInitAll=false;
2343 	eMenuState = _ms;
2344 	eOldMenuState = NOP;
2345 	eOldMenuWindowState= NOP;
2346 	pTexBackGround = NULL;
2347 	pTexBackGround1 = NULL;
2348 	fPos = 0;
2349 	pMenuAllZone=new CMenuAllZone();
2350 
2351 	iPosMenu=-1;
2352 }
2353 
~CMenuState()2354 CMenuState::~CMenuState() {
2355 	delete pMenuAllZone;
2356 	delete pTexBackGround;
2357 	delete pTexBackGround1;
2358 }
2359 
AddMenuElement(CMenuElement * _me)2360 void CMenuState::AddMenuElement(CMenuElement * _me) {
2361 	pMenuAllZone->AddZone((CMenuZone *)_me);
2362 }
2363 
Update(int _iDTime)2364 MENUSTATE CMenuState::Update(int _iDTime) {
2365 
2366 	fPos += _iDTime*( 1.0f / 700 );
2367 
2368 	pZoneClick=NULL;
2369 
2370 	CMenuZone * iR=pMenuAllZone->CheckZone(GInput->getMousePosAbs());
2371 
2372 	if(GInput->getMouseButton(Mouse::Button_0)) {
2373 		if(iR) {
2374 			pZoneClick = (CMenuElement*)iR;
2375 			pZoneClick->OnMouseClick(1);
2376 			return pZoneClick->eMenuState;
2377 		}
2378 	} else {
2379 		if(iR) {
2380 			pZoneClick = (CMenuElement*)iR;
2381 		}
2382 	}
2383 
2384 	return NOP;
2385 }
2386 
2387 //-----------------------------------------------------------------------------
2388 
Render()2389 void CMenuState::Render()
2390 {
2391 	if(bNoMenu) return;
2392 
2393 	if (pTexBackGround)
2394 		EERIEDrawBitmap2(0, 0, static_cast<float>(DANAESIZX), static_cast<float>(DANAESIZY), 0.999f, pTexBackGround, Color::white);
2395 
2396 	//------------------------------------------------------------------------
2397 
2398 	int t=pMenuAllZone->GetNbZone();
2399 
2400 	int iARXDiffTimeMenu = checked_range_cast<int>(ARXDiffTimeMenu);
2401 
2402 
2403 	for(int i=0;i<t;++i)
2404 	{
2405 		CMenuElement *pMe=(CMenuElement*)pMenuAllZone->GetZoneNum(i);
2406 		pMe->Update(iARXDiffTimeMenu);
2407 		pMe->Render();
2408 	}
2409 
2410 	//HIGHLIGHT
2411 	if(pZoneClick)
2412 	{
2413 		pZoneClick->RenderMouseOver();
2414 	}
2415 
2416 	//DEBUG ZONE
2417 	GRenderer->ResetTexture(0);
2418 	pMenuAllZone->DrawZone();
2419 }
2420 
2421 //-----------------------------------------------------------------------------
2422 
CMenuZone()2423 CMenuZone::CMenuZone()
2424 {
2425 	bActif = true;
2426 	bCheck=true;
2427 	bTestYDouble=false;
2428 	iID=-1;
2429 	lData=0;
2430 	pData=NULL;
2431 	lPosition=0;
2432 
2433 	rZone.top = 0;
2434 	rZone.bottom = 0;
2435 	rZone.left = 0;
2436 	rZone.right = 0;
2437 }
2438 
2439 //-----------------------------------------------------------------------------
2440 
CMenuZone(int _iX1,int _iY1,int _iX2,int _iY2,CMenuZone * _pRef)2441 CMenuZone::CMenuZone(int _iX1,int _iY1,int _iX2,int _iY2, CMenuZone * _pRef)
2442 {
2443 	bActif=true;
2444 	rZone.left=_iX1;
2445 	rZone.top=_iY1;
2446 	rZone.right=_iX2;
2447 	rZone.bottom=_iY2;
2448 	pRef=_pRef;
2449 
2450 	iID=-1;
2451 	lData=0;
2452 	pData=NULL;
2453 }
2454 
2455 //-----------------------------------------------------------------------------
2456 
~CMenuZone()2457 CMenuZone::~CMenuZone()
2458 {
2459 
2460 }
2461 
2462 //-----------------------------------------------------------------------------
2463 
Move(int _iX,int _iY)2464 void CMenuZone::Move(int _iX,int _iY)
2465 	{
2466 	rZone.left        += _iX;
2467 	rZone.top        += _iY;
2468 	rZone.right        += _iX;
2469 	rZone.bottom    += _iY;
2470 }
2471 
2472 //-----------------------------------------------------------------------------
2473 
SetPos(float _fX,float _fY)2474 void CMenuZone::SetPos(float _fX,float _fY)
2475 {
2476 	int iWidth        = rZone.right - rZone.left;
2477 	int iHeight        = rZone.bottom - rZone.top;
2478 
2479 	int iX = checked_range_cast<int>(_fX);
2480 	int iY = checked_range_cast<int>(_fY);
2481 
2482 	rZone.left        = iX;
2483 	rZone.top        = iY;
2484 	rZone.right        = iX + abs(iWidth);
2485 	rZone.bottom    = iY + abs(iHeight);
2486 }
2487 
2488 //-----------------------------------------------------------------------------
2489 
IsMouseOver(const Vec2s & mousePos) const2490 CMenuZone * CMenuZone::IsMouseOver(const Vec2s& mousePos) const
2491 {
2492 	int iYDouble=0;
2493 
2494 	if(bTestYDouble)
2495 	{
2496 		iYDouble=(rZone.bottom-rZone.top)>>1;
2497 	}
2498 
2499 	if(    bActif &&
2500 		(mousePos.x >= rZone.left) &&
2501 		(mousePos.y >= (rZone.top-iYDouble)) &&
2502 		(mousePos.x <= rZone.right) &&
2503 		(mousePos.y <= (rZone.bottom+iYDouble)) )
2504 		return pRef;
2505 
2506 	return NULL;
2507 }
2508 
2509 //-----------------------------------------------------------------------------
2510 
CMenuAllZone()2511 CMenuAllZone::CMenuAllZone()
2512 {
2513 	vMenuZone.clear();
2514 
2515 	vector<CMenuZone*>::iterator i;
2516 
2517 	for(i=vMenuZone.begin();i!=vMenuZone.end();++i)
2518 	{
2519 		CMenuZone *zone=*i;
2520 		delete zone;
2521 	}
2522 }
2523 
2524 //-----------------------------------------------------------------------------
2525 
~CMenuAllZone()2526 CMenuAllZone::~CMenuAllZone()
2527 {
2528 	for(std::vector<CMenuZone*>::iterator it = vMenuZone.begin(), it_end = vMenuZone.end(); it != it_end; ++it)
2529 		delete *it;
2530 }
2531 
2532 //-----------------------------------------------------------------------------
2533 
AddZone(CMenuZone * _pMenuZone)2534 void CMenuAllZone::AddZone(CMenuZone *_pMenuZone)
2535 {
2536 	vMenuZone.push_back(_pMenuZone);
2537 }
2538 
2539 //-----------------------------------------------------------------------------
2540 
CheckZone(const Vec2s & mousePos) const2541 CMenuZone * CMenuAllZone::CheckZone(const Vec2s& mousePos) const
2542 {
2543 	std::vector<CMenuZone*>::const_iterator i;
2544 
2545 	for(i=vMenuZone.begin();i!=vMenuZone.end();++i)
2546 	{
2547 		CMenuZone *zone=*i;
2548 
2549 		if(zone->bCheck && zone->bActif)
2550 		{
2551 			CMenuZone * pRef = ((*i)->IsMouseOver(mousePos));
2552 
2553             if (pRef)
2554                 return pRef;
2555 		}
2556 	}
2557 
2558 	return NULL;
2559 }
2560 
2561 //-----------------------------------------------------------------------------
2562 
GetZoneNum(int _iNum)2563 CMenuZone * CMenuAllZone::GetZoneNum(int _iNum)
2564 {
2565 	vector<CMenuZone*>::iterator i;
2566 	int iNum=0;
2567 
2568 	for(i=vMenuZone.begin();i!=vMenuZone.end();++i)
2569 	{
2570 		CMenuZone *zone=*i;
2571 
2572 		if(iNum==_iNum) return zone;
2573 
2574 		iNum++;
2575 	}
2576 
2577 	return NULL;
2578 }
2579 
2580 //-----------------------------------------------------------------------------
2581 
GetZoneWithID(int _iID)2582 CMenuZone * CMenuAllZone::GetZoneWithID(int _iID)
2583 {
2584 	for (std::vector<CMenuZone*>::iterator i = vMenuZone.begin(), i_end = vMenuZone.end(); i != i_end; ++i)
2585 		if (CMenuZone *zone = ((CMenuElement*)(*i))->GetZoneWithID(_iID))
2586 			return zone;
2587 
2588 	return NULL;
2589 }
2590 
2591 //-----------------------------------------------------------------------------
2592 
Move(int _iPosX,int _iPosY)2593 void CMenuAllZone::Move(int _iPosX,int _iPosY)
2594 {
2595 	for (std::vector<CMenuZone*>::iterator i = vMenuZone.begin(), i_end = vMenuZone.end(); i != i_end; ++i)
2596 		(*i)->Move(_iPosX, _iPosY);
2597 }
2598 
2599 //-----------------------------------------------------------------------------
2600 
GetNbZone()2601 int CMenuAllZone::GetNbZone()
2602 {
2603 	return vMenuZone.size();
2604 }
2605 
2606 //-----------------------------------------------------------------------------
2607 
DrawZone()2608 void CMenuAllZone::DrawZone()
2609 {
2610 #ifndef NODEBUGZONE
2611 	GRenderer->SetBlendFunc(Renderer::BlendOne, Renderer::BlendOne);
2612 	GRenderer->SetRenderState(Renderer::AlphaBlending, true);
2613 
2614 	GRenderer->ResetTexture(0);
2615 
2616 	for(std::vector<CMenuZone*>::const_iterator i = vMenuZone.begin(), i_end = vMenuZone.end(); i != i_end; ++i)
2617 	{
2618 		CMenuZone *zone=*i;
2619 
2620 		if(zone->bActif)
2621 		{
2622 			TexturedVertex v1[3],v2[3];
2623 			v1[0].p.x = (float)zone->rZone.left;
2624 			v1[0].p.y = (float)zone->rZone.top;
2625 			v1[1].p.x = (float)zone->rZone.left;
2626 			v1[1].p.y = (float)zone->rZone.bottom;
2627 			v1[2].p.x = (float)zone->rZone.right;
2628 			v1[2].p.y = (float)zone->rZone.bottom;
2629 
2630 			v2[0].p.x = (float)zone->rZone.left;
2631 			v2[0].p.y = (float)zone->rZone.top;
2632 			v2[1].p.x = (float)zone->rZone.right;
2633 			v2[1].p.y = (float)zone->rZone.top;
2634 			v2[2].p.x = (float)zone->rZone.right;
2635 			v2[2].p.y = (float)zone->rZone.bottom;
2636 
2637 			v1[0].color=v1[1].color=v1[2].color=v2[0].color=v2[1].color=v2[2].color=0xFFFFA000;
2638 			v1[0].p.z=v1[1].p.z=v1[2].p.z=v2[0].p.z=v2[1].p.z=v2[2].p.z=0.f;
2639 			v1[0].rhw=v1[1].rhw=v1[2].rhw=v2[0].rhw=v2[1].rhw=v2[2].rhw=0.999999f;
2640 
2641 			EERIEDRAWPRIM(Renderer::TriangleStrip, v1);
2642 			EERIEDRAWPRIM(Renderer::TriangleStrip, v2);
2643 		}
2644 	}
2645 
2646 	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
2647 #endif // #ifndef NODEBUGZONE
2648 }
2649 
2650 //-----------------------------------------------------------------------------
2651 
CMenuCheckButton(int _iID,float _fPosX,float _fPosY,int _iTaille,TextureContainer * _pTex1,TextureContainer * _pTex2,CMenuElementText * _pText)2652 CMenuCheckButton::CMenuCheckButton(int _iID, float _fPosX,float _fPosY,int _iTaille,TextureContainer *_pTex1,TextureContainer *_pTex2, CMenuElementText *_pText)
2653 	:CMenuElement(NOP)
2654 {
2655 	iID = _iID;
2656 	iState    = 0;
2657 	iOldState = -1;
2658 
2659 	iPosX = checked_range_cast<int>(_fPosX);
2660 	iPosY = checked_range_cast<int>(_fPosY);
2661 
2662 	iTaille = _iTaille;
2663 
2664 	pText    = _pText;
2665 
2666 	if(_pTex1) {
2667 		float fRatioX = RATIO_X(_pTex1->m_dwWidth) ;
2668 		float fRatioY = RATIO_Y(_pTex1->m_dwHeight);
2669 		vTex.push_back(_pTex1);
2670 		_iTaille = std::max(_iTaille, checked_range_cast<int>(fRatioX));
2671 		_iTaille = std::max(_iTaille, checked_range_cast<int>(fRatioY));
2672 	}
2673 
2674 	if(_pTex2) {
2675 		float fRatioX = RATIO_X(_pTex2->m_dwWidth) ;
2676 		float fRatioY = RATIO_Y(_pTex2->m_dwHeight);
2677 		vTex.push_back(_pTex2);
2678 		_iTaille = std::max(_iTaille, checked_range_cast<int>(fRatioX));
2679 		_iTaille = std::max(_iTaille, checked_range_cast<int>(fRatioY));
2680 	}
2681 
2682 	Vec2i textSize(0,0);
2683 
2684 	if ( pText )
2685 	{
2686 		textSize = pText->pFont->getTextSize(pText->lpszText);
2687 
2688 		_iTaille = std::max<int>(_iTaille, textSize.y);
2689 		textSize.x += pText->rZone.left;
2690 		pText->Move(iPosX, iPosY + (_iTaille - textSize.y) / 2);
2691 	}
2692 
2693 	rZone.left = checked_range_cast<Rect::Num>(_fPosX);
2694 	rZone.top = checked_range_cast<Rect::Num>(_fPosY);
2695 	rZone.right = checked_range_cast<Rect::Num>(_fPosX + _iTaille + textSize.x);
2696 	rZone.bottom = checked_range_cast<Rect::Num>(_fPosY + std::max<int>(_iTaille, textSize.y));
2697 	pRef=this;
2698 
2699 	if(_pTex1 && _pTex2) {
2700 		float rZoneR = ( RATIO_X(200.f) + RATIO_X(_pTex1->m_dwWidth) + (RATIO_X(12*9) - RATIO_X(_pTex1->m_dwWidth))*0.5f );
2701 		rZone.right = checked_range_cast<Rect::Num>(rZoneR);
2702 	}
2703 
2704 	Move(iPosX, iPosY);
2705 }
2706 
~CMenuCheckButton()2707 CMenuCheckButton::~CMenuCheckButton() {
2708 	delete pText;
2709 }
2710 
Move(int _iX,int _iY)2711 void CMenuCheckButton::Move(int _iX, int _iY) {
2712 
2713 	CMenuElement::Move(_iX, _iY);
2714 
2715 	if(pText) {
2716 		pText->Move(_iX, _iY);
2717 	}
2718 
2719 	ComputeTexturesPosition();
2720 }
2721 
OnMouseClick(int _iMouseButton)2722 bool CMenuCheckButton::OnMouseClick(int _iMouseButton) {
2723 
2724 	(void)_iMouseButton;
2725 
2726 	if(iOldState<0)
2727 		iOldState=iState;
2728 
2729 	iState ++;
2730 
2731 	//NB : It seems that iState cannot be negative (used as tabular index / used as bool) but need further approval
2732 	arx_assert(iState >= 0);
2733 
2734 	if ((size_t)iState >= vTex.size())
2735 	{
2736 
2737 		iState = 0;
2738 	}
2739 
2740 	ARX_SOUND_PlayMenu(SND_MENU_CLICK);
2741 
2742 	switch (iID)
2743 	{
2744 	case BUTTON_MENUOPTIONSVIDEO_FULLSCREEN:
2745 		{
2746 			newFullscreen = ((iState)?true:false);
2747 
2748 			if(pMenuSliderResol) {
2749 				pMenuSliderResol->setEnabled(newFullscreen);
2750 			}
2751 			if(pMenuSliderBpp) {
2752 				pMenuSliderBpp->setEnabled(newFullscreen);
2753 			}
2754 
2755 		}
2756 		break;
2757 	case BUTTON_MENUOPTIONSVIDEO_CROSSHAIR:
2758 		{
2759 			config.video.showCrosshair=(iState)?true:false;
2760 		}
2761 		break;
2762 	case BUTTON_MENUOPTIONSVIDEO_ANTIALIASING: {
2763 		config.video.antialiasing = iState ? true : false;
2764 		ARX_SetAntiAliasing();
2765 		break;
2766 	}
2767 	case BUTTON_MENUOPTIONSVIDEO_VSYNC: {
2768 		config.video.vsync = iState ? true : false;
2769 		break;
2770 	}
2771 	case BUTTON_MENUOPTIONSAUDIO_EAX:
2772 		{
2773 			ARXMenu_Options_Audio_SetEAX((iState)?true:false);
2774 		}
2775 		break;
2776 	case BUTTON_MENUOPTIONS_CONTROLS_INVERTMOUSE:
2777 		{
2778 			ARXMenu_Options_Control_SetInvertMouse((iState)?true:false);
2779 		}
2780 		break;
2781 	case BUTTON_MENUOPTIONS_CONTROLS_AUTOREADYWEAPON: {
2782 		config.input.autoReadyWeapon = (iState) ? true : false;
2783 		break;
2784 	}
2785 	case BUTTON_MENUOPTIONS_CONTROLS_MOUSELOOK: {
2786 		config.input.mouseLookToggle = (iState) ? true : false;
2787 		break;
2788 	}
2789 	case BUTTON_MENUOPTIONS_CONTROLS_AUTODESCRIPTION: {
2790 		config.input.autoDescription = (iState) ? true : false;
2791 		break;
2792 	}
2793 	case BUTTON_MENUOPTIONS_CONTROLS_LINK: {
2794 		config.input.linkMouseLookToUse = (iState) ? true : false;
2795 		break;
2796 	}
2797 	case BUTTON_MENUOPTIONSVIDEO_BACK:
2798 	{
2799 		if(    (pMenuSliderResol)&&
2800 			(pMenuSliderResol->iOldPos>=0) )
2801 		{
2802 			pMenuSliderResol->iPos=pMenuSliderResol->iOldPos;
2803 			pMenuSliderResol->iOldPos=-1;
2804 			newWidth=config.video.resolution.x;
2805 			newHeight=config.video.resolution.y;
2806 		}
2807 
2808 		if(    (pMenuSliderBpp)&&
2809 			(pMenuSliderBpp->iOldPos>=0) )
2810 		{
2811 			pMenuSliderBpp->iPos=pMenuSliderBpp->iOldPos;
2812 			pMenuSliderBpp->iOldPos=-1;
2813 			newBpp=config.video.bpp;
2814 		}
2815 
2816 		if(fullscreenCheckbox && fullscreenCheckbox->iOldState >= 0) {
2817 			fullscreenCheckbox->iState = fullscreenCheckbox->iOldState;
2818 			fullscreenCheckbox->iOldState = -1;
2819 			newFullscreen = config.video.fullscreen;
2820 		}
2821 		break;
2822 	}
2823 
2824 	}
2825 
2826 	return false;
2827 }
2828 
2829 //-----------------------------------------------------------------------------
2830 
Update(int)2831 void CMenuCheckButton::Update(int /*_iDTime*/)
2832 {
2833 }
2834 
2835 //-----------------------------------------------------------------------------
2836 
Render()2837 void CMenuCheckButton::Render()
2838 {
2839 	if(bNoMenu) return;
2840 
2841 	GRenderer->SetRenderState(Renderer::AlphaBlending, true);
2842 	GRenderer->SetBlendFunc(Renderer::BlendOne, Renderer::BlendOne);
2843 
2844 	if (!vTex.empty())
2845 	{
2846 		TextureContainer *pTex = vTex[iState];
2847 
2848 		TexturedVertex v[4];
2849 		Color color = (bCheck) ? Color::white : Color::fromBGRA(0xFF3F3F3F);
2850 
2851 		v[0].p.z=v[1].p.z=v[2].p.z=v[3].p.z=0.f;
2852 		v[0].rhw=v[1].rhw=v[2].rhw=v[3].rhw=0.999999f;
2853 
2854 		float iY = 0;
2855 
2856 		{
2857 			iY = static_cast<float>(rZone.bottom - rZone.top);
2858 			iY -= iTaille;
2859 			iY = rZone.top + iY*0.5f;
2860 		}
2861 
2862 		//carre
2863 		EERIEDrawBitmap2(static_cast<float>(rZone.right - iTaille), iY, RATIO_X(iTaille), RATIO_Y(iTaille), 0.f, pTex, color);
2864 	}
2865 
2866 	if (pText)
2867 		pText->Render();
2868 
2869 	//DEBUG
2870 	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
2871 }
2872 
2873 //-----------------------------------------------------------------------------
2874 
RenderMouseOver()2875 void CMenuCheckButton::RenderMouseOver()
2876 {
2877 	if(bNoMenu) return;
2878 
2879 	pMenuCursor->SetMouseOver();
2880 
2881 	GRenderer->SetRenderState(Renderer::AlphaBlending, true);
2882 	GRenderer->SetBlendFunc(Renderer::BlendOne, Renderer::BlendOne);
2883 
2884 	TextureContainer *pTex = vTex[iState];
2885 
2886 	if(pTex) GRenderer->SetTexture(0, pTex);
2887 	else GRenderer->ResetTexture(0);
2888 
2889 	TexturedVertex v[4];
2890 	v[0].color = v[1].color = v[2].color = v[3].color = Color::white.toBGR();
2891 	v[0].p.z=v[1].p.z=v[2].p.z=v[3].p.z=0.f;
2892 	v[0].rhw=v[1].rhw=v[2].rhw=v[3].rhw=0.999999f;
2893 
2894 	float iY = 0;
2895 	iY = static_cast<float>(rZone.bottom - rZone.top);
2896 	iY -= iTaille;
2897 	iY = rZone.top + iY*0.5f;
2898 
2899 	//carre
2900 
2901 	EERIEDrawBitmap2(static_cast<float>(rZone.right - iTaille), iY, RATIO_X(iTaille), RATIO_Y(iTaille), 0.f, pTex, Color::white);
2902 
2903 
2904 	//tick
2905 	if (pText)
2906 		pText->RenderMouseOver();
2907 
2908 	//DEBUG
2909 	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
2910 }
2911 
2912 //-----------------------------------------------------------------------------
2913 
2914 // Nuky - merges common code of Render() and RenderMouseOver()
2915 /// Compute members fTexX, fTexY, fTexSX and fTexSY according to rZone and iTaille
ComputeTexturesPosition()2916 void CMenuCheckButton::ComputeTexturesPosition()
2917 {
2918 	// Nuky - for now I split into 2 cases, because I don't know yet how to fix position with text
2919 	// TODO Merge with master
2920 	/*if (!pText)
2921 	{
2922 		fTexX_ = static_cast<float>(rZone.left);
2923 		fTexY_ = static_cast<float>(rZone.top);
2924 		fTexSX_ = RATIO_X(iTaille);
2925 		fTexSY_ = RATIO_Y(iTaille);
2926 	}
2927 	else
2928 	{
2929 		fTexX_ = static_cast<float>(rZone.right - iTaille);
2930 		fTexY_ = rZone.top + (static_cast<float>(rZone.bottom - rZone.top) - iTaille) * 0.5f;
2931 		fTexSX_ = RATIO_X(iTaille);
2932 		fTexSY_ = RATIO_Y(iTaille);
2933 	}*/
2934 }
2935 
2936 //-----------------------------------------------------------------------------
2937 
CWindowMenu(int _iPosX,int _iPosY,int _iTailleX,int _iTailleY,int _iNbButton)2938 CWindowMenu::CWindowMenu(int _iPosX,int _iPosY,int _iTailleX,int _iTailleY,int _iNbButton) :
2939 	bMouseListen (true)
2940 {
2941 	iPosX=(int)RATIO_X(_iPosX);
2942 	iPosY=(int)RATIO_Y(_iPosY);
2943 	iTailleX=(int)RATIO_X(_iTailleX);
2944 	iTailleY=(int)RATIO_Y(_iTailleY);
2945 	iNbButton=_iNbButton;
2946 
2947 	pTexButton=TextureContainer::LoadUI("graph/interface/menus/menu_left_1button");
2948 	pTexButton2=TextureContainer::LoadUI("graph/interface/menus/menu_left_2button");
2949 	pTexButton3=TextureContainer::LoadUI("graph/interface/menus/menu_left_3button");
2950 
2951 	pTexMain=TextureContainer::LoadUI("graph/interface/menus/menu_left_main");
2952 
2953 	pTexGlissiere=TextureContainer::LoadUI("graph/interface/menus/menu_left_main_glissiere");
2954 	pTexGlissiereButton=TextureContainer::LoadUI("graph/interface/menus/menu_left_main_glissiere_button");
2955 
2956 	vWindowConsoleElement.clear();
2957 
2958 	fPosXCalc=((float)-iTailleX);
2959 	fDist=((float)(iTailleX+iPosX));
2960 	fAngle=0.f;
2961 
2962 	eCurrentMenuState=NOP;
2963 
2964 
2965 	float fCalc	= fPosXCalc + (fDist * sin(radians(fAngle)));
2966 
2967 	iPosX = checked_range_cast<int>(fCalc);
2968 
2969 	bChangeConsole=false;
2970 }
2971 
2972 //-----------------------------------------------------------------------------
2973 
~CWindowMenu()2974 CWindowMenu::~CWindowMenu()
2975 {
2976 	for (std::vector<CWindowMenuConsole*>::iterator it = vWindowConsoleElement.begin(), it_end = vWindowConsoleElement.end(); it < it_end; ++it)
2977 		delete *it;
2978 }
2979 
2980 //-----------------------------------------------------------------------------
2981 
AddConsole(CWindowMenuConsole * _pMenuConsoleElement)2982 void CWindowMenu::AddConsole(CWindowMenuConsole *_pMenuConsoleElement)
2983 {
2984 	vWindowConsoleElement.push_back(_pMenuConsoleElement);
2985 	_pMenuConsoleElement->iOldPosX = 0;
2986 	_pMenuConsoleElement->iOldPosY = 0;
2987 	_pMenuConsoleElement->iPosX = iPosX;
2988 	_pMenuConsoleElement->iPosY = iPosY;
2989 }
2990 
2991 //-----------------------------------------------------------------------------
2992 
Update(float _fDTime)2993 void CWindowMenu::Update(float _fDTime)
2994 {
2995 
2996 
2997 	float fCalc	= fPosXCalc + (fDist * sin(radians(fAngle)));
2998 
2999 	iPosX = checked_range_cast<int>(fCalc);
3000 
3001 	fAngle += _fDTime * 0.08f;
3002 
3003 	if (fAngle>90.f) fAngle=90.f;
3004 }
3005 
3006 //-----------------------------------------------------------------------------
3007 
Render()3008 MENUSTATE CWindowMenu::Render()
3009 {
3010 	if(bNoMenu) return NOP;
3011 
3012 	if(bChangeConsole)
3013 	{
3014 		//TO DO: faire ce que l'on veut
3015 
3016 		bChangeConsole=false;
3017 	}
3018 
3019 	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
3020 
3021 	TexturedVertex v[4];
3022 	v[0].color = v[1].color = v[2].color = v[3].color = Color::white.toBGR();
3023 	v[0].p.z=v[1].p.z=v[2].p.z=v[3].p.z=0.f;
3024 	v[0].rhw=v[1].rhw=v[2].rhw=v[3].rhw=0.999999f;
3025 
3026 	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
3027 	GRenderer->SetBlendFunc(Renderer::BlendOne, Renderer::BlendOne);
3028 
3029 	MENUSTATE eMS=NOP;
3030 
3031 	if (bMouseListen)
3032 	{
3033 		vector<CWindowMenuConsole*>::iterator i;
3034 
3035 		for (i = vWindowConsoleElement.begin(); i != vWindowConsoleElement.end(); ++i)
3036 		{
3037 			if(eCurrentMenuState==(*i)->eMenuState)
3038 			{
3039 				eMS=(*i)->Update(iPosX, iPosY, 0);
3040 
3041 				if (eMS != NOP)
3042 					break;
3043 			}
3044 		}
3045 	}
3046 
3047 	for (std::vector<CWindowMenuConsole*>::iterator i = vWindowConsoleElement.begin(); i != vWindowConsoleElement.end(); ++i)
3048 	{
3049 		if(eCurrentMenuState==(*i)->eMenuState)
3050 		{
3051 			if ((*i)->Render())
3052 				GRenderer->SetRenderState(Renderer::AlphaBlending, false);
3053 
3054 			break;
3055 		}
3056 	}
3057 
3058 	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
3059 
3060 	if (eMS != NOP)
3061 	{
3062 		eCurrentMenuState=eMS;
3063 		bChangeConsole=true;
3064 	}
3065 
3066 	return eMS;
3067 }
3068 
CWindowMenuConsole(int _iPosX,int _iPosY,int _iWidth,int _iHeight,MENUSTATE _eMenuState)3069 CWindowMenuConsole::CWindowMenuConsole(int _iPosX,int _iPosY,int _iWidth,int _iHeight,MENUSTATE _eMenuState) :
3070 	bMouseListen (true),
3071 	iInterligne (10),
3072 	bEdit (false),
3073 	lData(0),
3074 	pData(NULL)
3075 {
3076 	iOX=(int)RATIO_X(_iPosX);
3077 	iOY=(int)RATIO_Y(_iPosY);
3078 	iWidth=(int)RATIO_X(_iWidth);
3079 	iHeight=(int)RATIO_Y(_iHeight);
3080 
3081 	eMenuState=_eMenuState;
3082 
3083 	pTexBackground = TextureContainer::LoadUI("graph/interface/menus/menu_console_background");
3084 	pTexBackgroundBorder = TextureContainer::LoadUI("graph/interface/menus/menu_console_background_border");
3085 
3086 	bFrameOdd=false;
3087 
3088 	iPosMenu=-1;
3089 }
3090 
3091 //-----------------------------------------------------------------------------
3092 
AddMenu(CMenuElement * _pMenuElement)3093 void CWindowMenuConsole::AddMenu(CMenuElement *_pMenuElement)
3094 {
3095 	_pMenuElement->ePlace=NOCENTER;
3096 
3097 	_pMenuElement->Move(iOX,iOY);
3098 	MenuAllZone.AddZone((CMenuZone*)_pMenuElement);
3099 }
3100 
3101 //-----------------------------------------------------------------------------
3102 
AddMenuCenterY(CMenuElement * _pMenuElement)3103 void CWindowMenuConsole::AddMenuCenterY( CMenuElement * _pMenuElement )
3104 {
3105 	_pMenuElement->ePlace    =    CENTERY;
3106 	int iDy                    =    _pMenuElement->rZone.bottom-_pMenuElement->rZone.top;
3107 
3108 	int iI                    =    MenuAllZone.GetNbZone();
3109 
3110 	for( int iJ = 0 ; iJ < iI ; iJ++ )
3111 	{
3112 		iDy +=    iInterligne;
3113 		CMenuZone    *pZone    =    MenuAllZone.GetZoneNum(iJ);
3114 		iDy    +=    pZone->rZone.bottom - pZone->rZone.top;
3115 	}
3116 
3117 	int iDepY;
3118 
3119 	if( iDy < iHeight )
3120 	{
3121 		iDepY = iOY + ( ( iHeight - iDy ) >> 1 );
3122 	}
3123 	else
3124 	{
3125 		iDepY = iOY;
3126 	}
3127 
3128 	int dy = 0;
3129 	iI = MenuAllZone.GetNbZone();
3130 
3131 	if( iI )
3132 	{
3133 		dy    =    iDepY - MenuAllZone.GetZoneNum(0)->rZone.top;
3134 	}
3135 
3136 	//We can't go inside the for-loop
3137 	else
3138 	{
3139 		arx_assert( !( 0 < iI ) );
3140 	}
3141 
3142 	for( int iJ = 0 ; iJ < iI ; iJ++ )
3143 	{
3144 		CMenuZone *pZone    =    MenuAllZone.GetZoneNum(iJ);
3145 		iDy                    =    pZone->rZone.bottom - pZone->rZone.top;
3146 		iDepY                +=    iDy + iInterligne;
3147 		pZone->Move( 0, dy );
3148 	}
3149 
3150 	_pMenuElement->Move( 0, iDepY );
3151 
3152 	MenuAllZone.AddZone( (CMenuZone*) _pMenuElement );
3153 }
3154 
3155 //-----------------------------------------------------------------------------
3156 
AddMenuCenter(CMenuElement * _pMenuElement)3157 void CWindowMenuConsole::AddMenuCenter( CMenuElement * _pMenuElement )
3158 {
3159 	_pMenuElement->ePlace    =    CENTER;
3160 
3161 	int    iDx    =    _pMenuElement->rZone.right - _pMenuElement->rZone.left;
3162 	int    dx    =    ( ( iWidth - iDx ) >> 1 ) - _pMenuElement->rZone.left;
3163 
3164 	if( dx < 0 )
3165 	{
3166 		dx = 0;
3167 	}
3168 
3169 	int    iDy    =    _pMenuElement->rZone.bottom - _pMenuElement->rZone.top;
3170 	int    iI    =    MenuAllZone.GetNbZone();
3171 
3172 	for( int iJ = 0 ; iJ < iI ; iJ++ )
3173 	{
3174 		iDy    +=    iInterligne;
3175 		CMenuZone *pZone    =    MenuAllZone.GetZoneNum(iJ);
3176 		iDy    +=    pZone->rZone.bottom - pZone->rZone.top;
3177 	}
3178 
3179 	int iDepY;
3180 
3181 	if( iDy < iHeight )
3182 	{
3183 		iDepY    =    iOY + ( ( iHeight - iDy ) >> 1 );
3184 	}
3185 	else
3186 	{
3187 		iDepY    =    iOY;
3188 	}
3189 
3190 	int dy = 0;
3191 	iI = MenuAllZone.GetNbZone();
3192 
3193 	if( iI )
3194 	{
3195 		dy    =    iDepY - MenuAllZone.GetZoneNum(0)->rZone.top;
3196 	}
3197 
3198 	//We can't go inside the for-loop
3199 	else
3200 	{
3201 		arx_assert( !( 0 < iI ) );
3202 	}
3203 
3204 	for( int iJ = 0 ; iJ < iI ; iJ++ )
3205 	{
3206 		CMenuZone *pZone = MenuAllZone.GetZoneNum( iJ );
3207 		iDepY += pZone->rZone.bottom - pZone->rZone.top + iInterligne;
3208 		pZone->Move( 0, dy );
3209 	}
3210 
3211 	_pMenuElement->Move( dx, iDepY );
3212 
3213 	MenuAllZone.AddZone( (CMenuZone*) _pMenuElement );
3214 }
3215 
3216 //-----------------------------------------------------------------------------
3217 
AlignElementCenter(CMenuElement * _pMenuElement)3218 void CWindowMenuConsole::AlignElementCenter(CMenuElement *_pMenuElement) {
3219 
3220 	_pMenuElement->Move(-_pMenuElement->rZone.left, 0);
3221 	_pMenuElement->ePlace = CENTER;
3222 
3223 	int iDx = _pMenuElement->rZone.right - _pMenuElement->rZone.left;
3224 	int dx = (iWidth - iDx) / 2 - _pMenuElement->rZone.left;
3225 
3226 	_pMenuElement->Move(std::max(dx, 0), 0);
3227 }
3228 
3229 //-----------------------------------------------------------------------------
3230 
UpdateText()3231 void CWindowMenuConsole::UpdateText()
3232 {
3233 	if(GInput->isAnyKeyPressed())
3234 	{
3235 		if( (GInput->isKeyPressed(Keyboard::Key_Enter)) ||
3236 			(GInput->isKeyPressed(Keyboard::Key_NumPadEnter)) ||
3237 			(GInput->isKeyPressed(Keyboard::Key_Escape)) )
3238 		{
3239 			ARX_SOUND_PlayMenu(SND_MENU_CLICK);
3240 			((CMenuElementText*)pZoneClick)->eState=EDIT;
3241 
3242 			if( ((CMenuElementText*)pZoneClick)->lpszText.empty() )
3243 			{
3244 				std::string szMenuText;
3245 				szMenuText = getLocalised("system_menu_editquest_newsavegame");
3246 
3247 				((CMenuElementText*)pZoneClick)->SetText(szMenuText);
3248 
3249 				int iDx=pZoneClick->rZone.right-pZoneClick->rZone.left;
3250 
3251 				if(pZoneClick->ePlace)
3252 				{
3253 					pZoneClick->rZone.left=iPosX+((iWidth-iDx)>>1);
3254 
3255 					if(pZoneClick->rZone.left<0)
3256 					{
3257 						pZoneClick->rZone.left=0;
3258 					}
3259 				}
3260 
3261 				pZoneClick->rZone.right=pZoneClick->rZone.left+iDx;
3262 			}
3263 
3264 			pZoneClick=NULL;
3265 			bEdit=false;
3266 			return;
3267 		}
3268 
3269 		bool bKey=false;
3270 		std::string tText;
3271 
3272 		CMenuElementText *pZoneText=(CMenuElementText*)pZoneClick;
3273 
3274 		if(GInput->isKeyPressedNowPressed(Keyboard::Key_Backspace))
3275 		{
3276 			tText = pZoneText->lpszText;
3277 
3278 			if( !tText.empty() )
3279 			{
3280 				tText.resize(tText.size() - 1);
3281 				bKey=true;
3282 			}
3283 		}
3284 		else
3285 		{
3286 			int iKey = GInput->getKeyPressed();
3287 			iKey&=0xFFFF;
3288 
3289 			if(GInput->isKeyPressedNowPressed(iKey))
3290 			{
3291 				tText = pZoneText->lpszText;
3292 
3293 				char tCat;
3294 
3295 				bKey = GInput->getKeyAsText(iKey, tCat);
3296 
3297 				if(bKey)
3298 				{
3299 					int iChar = tCat & 0x000000FF; // To prevent ascii chars between [128, 255] from causing an assertion in the functions below...
3300 					if ((isalnum(iChar) || isspace(iChar) || ispunct(iChar)) && (tCat != '\t') && (tCat != '*'))
3301 						tText += tCat;
3302 				}
3303 			}
3304 		}
3305 
3306 		if(bKey)
3307 		{
3308 			pZoneText->SetText(tText);
3309 
3310 			if(    (pZoneText->rZone.right-pZoneText->rZone.left)>(iWidth-RATIO_X(64)) )
3311 			{
3312 				if(!tText.empty()) {
3313 					tText.resize(tText.size() - 1);
3314 					pZoneText->SetText(tText);
3315 				}
3316 			}
3317 
3318 			int iDx=pZoneClick->rZone.right-pZoneClick->rZone.left;
3319 
3320 			if(pZoneClick->ePlace)
3321 			{
3322 				pZoneClick->rZone.left=iPosX+((iWidth-iDx)>>1);
3323 
3324 				if(pZoneClick->rZone.left<0)
3325 				{
3326 					pZoneClick->rZone.left=0;
3327 				}
3328 			}
3329 
3330 			pZoneClick->rZone.right=pZoneClick->rZone.left+iDx;
3331 		}
3332 	}
3333 
3334 	if (pZoneClick->rZone.top == pZoneClick->rZone.bottom)
3335 	{
3336 		Vec2i textSize = ((CMenuElementText*)pZoneClick)->pFont->getTextSize("|");
3337 		pZoneClick->rZone.bottom += textSize.y;
3338 	}
3339 
3340 	//DRAW CURSOR
3341 	TexturedVertex v[4];
3342 	GRenderer->ResetTexture(0);
3343 	float col=.5f+rnd()*.5f;
3344 	v[0].color = v[1].color = v[2].color = v[3].color = Color::gray(col).toBGR();
3345 	v[0].p.z=v[1].p.z=v[2].p.z=v[3].p.z=0.f;
3346 	v[0].rhw=v[1].rhw=v[2].rhw=v[3].rhw=0.999999f;
3347 
3348 	v[0].p.x = (float)pZoneClick->rZone.right;
3349 	v[0].p.y = (float)pZoneClick->rZone.top;
3350 	v[1].p.x = v[0].p.x+2.f;
3351 	v[1].p.y = v[0].p.y;
3352 	v[2].p.x = v[0].p.x;
3353 	v[2].p.y = (float)pZoneClick->rZone.bottom;
3354 	v[3].p.x = v[1].p.x;
3355 	v[3].p.y = v[2].p.y;
3356 	EERIEDRAWPRIM(Renderer::TriangleStrip, v, 4);
3357 }
3358 
3359 //-----------------------------------------------------------------------------
3360 
GetTouch(bool keyTouched,int keyId,InputKeyId * pInputKeyId,bool _bValidateTest)3361 CMenuElement * CWindowMenuConsole::GetTouch(bool keyTouched, int keyId, InputKeyId* pInputKeyId, bool _bValidateTest)
3362 {
3363 	int iMouseButton = keyTouched ? 0 : GInput->getMouseButtonClicked();
3364 
3365 	if(pInputKeyId)
3366 		*pInputKeyId = keyId;
3367 
3368 	if(keyTouched || (iMouseButton & (Mouse::ButtonBase | Mouse::WheelBase))) {
3369 		if(!keyTouched && !bMouseAttack)
3370 		{
3371 			bMouseAttack=!bMouseAttack;
3372 			return NULL;
3373 		}
3374 
3375 		CMenuElementText *pZoneText=(CMenuElementText*)pZoneClick;
3376 
3377 		if(_bValidateTest)
3378 		{
3379 			if( (pZoneClick->iID==BUTTON_MENUOPTIONS_CONTROLS_CUST_ACTIONCOMBINE1)||
3380 				(pZoneClick->iID==BUTTON_MENUOPTIONS_CONTROLS_CUST_ACTIONCOMBINE2))
3381 			{
3382 				bool bOk=true;
3383 
3384 				if(  (iMouseButton & Mouse::ButtonBase)&&
3385 					!(iMouseButton & Mouse::WheelBase) )
3386 				{
3387 					bOk=false;
3388 				}
3389 				else
3390 				{
3391 					for(int buttonId = Mouse::ButtonBase; buttonId < Mouse::ButtonMax; buttonId++)
3392 					{
3393 						if(keyId == buttonId)
3394 						{
3395 							bOk=false;
3396 							break;
3397 						}
3398 					}
3399 				}
3400 
3401 				if(bOk) return NULL;
3402 			}
3403 		}
3404 
3405 		std::string pText;
3406 		if(iMouseButton & (Mouse::ButtonBase | Mouse::WheelBase))
3407 			pText = GInput->getKeyName(iMouseButton, true);
3408 		else
3409 			pText = GInput->getKeyName(keyId, true);
3410 
3411 		if ( !pText.empty() )
3412 		{
3413 			pZoneText->lColorHighlight=pZoneText->lOldColor;
3414 
3415 			pZoneText->eState=GETTOUCH;
3416 			pZoneText->SetText(pText);
3417 
3418 			int iDx=pZoneClick->rZone.right-pZoneClick->rZone.left;
3419 
3420 			if(pZoneClick->ePlace)
3421 			{
3422 				pZoneClick->rZone.left=(iWidth-iDx)>>1;
3423 
3424 				if(pZoneClick->rZone.left<0)
3425 				{
3426 					pZoneClick->rZone.left=0;
3427 				}
3428 			}
3429 
3430 			pZoneClick->rZone.right=pZoneClick->rZone.left+iDx;
3431 
3432 			pZoneClick=NULL;
3433 			bEdit=false;
3434 
3435 			if(iMouseButton & (Mouse::ButtonBase | Mouse::WheelBase))
3436 			{
3437 				if(pInputKeyId)
3438 					*pInputKeyId = iMouseButton;
3439 			}
3440 
3441 			bMouseAttack=false;
3442 
3443 			return (CMenuElement*)pZoneText;
3444 		}
3445 
3446 	}
3447 
3448 	return NULL;
3449 }
3450 
3451 //-----------------------------------------------------------------------------
3452 
Update(int _iPosX,int _iPosY,int _iOffsetY)3453 MENUSTATE CWindowMenuConsole::Update(int _iPosX,int _iPosY,int _iOffsetY)
3454 {
3455 	bFrameOdd=!bFrameOdd;
3456 
3457 	iSavePosY=_iPosY;
3458 
3459 	//move les zones
3460 	if(_iOffsetY)
3461 	{
3462 		_iPosY-=(MenuAllZone.GetZoneNum(_iOffsetY)->rZone.top)-(MenuAllZone.GetZoneNum(0)->rZone.top);
3463 	}
3464 
3465 	MenuAllZone.Move((iPosX-iOldPosX),(iPosY-iOldPosY));
3466 
3467 	int iI = MenuAllZone.GetNbZone();
3468 
3469 	for(int iJ=0;iJ<iI;++iJ)
3470 	{
3471 		CMenuZone *pZone = MenuAllZone.GetZoneNum(iJ);
3472 
3473 		if(    (pZone->rZone.top<iSavePosY)||
3474 			((pZone->rZone.bottom+iInterligne)>(iSavePosY+iHeight)))
3475 		{
3476 			pZone->bActif=false;
3477 		}
3478 		else
3479 		{
3480 			pZone->bActif=true;
3481 		}
3482 
3483 		pZone->bActif=true;
3484 	}
3485 
3486 	iOldPosX=iPosX;
3487 	iOldPosY=iPosY;
3488 	iPosX=_iPosX;
3489 	iPosY=_iPosY;
3490 
3491 	// Check if mouse over
3492 	if (bMouseListen)
3493 	{
3494 		if (!bEdit)
3495 		{
3496 			pZoneClick=NULL;
3497 			CMenuZone * iR = MenuAllZone.CheckZone(GInput->getMousePosAbs());
3498 
3499 			if(iR) {
3500 				pZoneClick=(CMenuElement*)iR;
3501 
3502 				if( GInput->getMouseButtonDoubleClick(Mouse::Button_0,300) )
3503 				{
3504 					MENUSTATE e = pZoneClick->eMenuState;
3505 					bEdit = pZoneClick->OnMouseDoubleClick(0);
3506 
3507 					if (pZoneClick->iID == BUTTON_MENUEDITQUEST_LOAD)
3508 						return MAIN;
3509 
3510 					if(bEdit)
3511 						return pZoneClick->eMenuState;
3512 
3513 					return e;
3514 				}
3515 
3516 				if( GInput->getMouseButton(Mouse::Button_0) )
3517 				{
3518 					MENUSTATE e = pZoneClick->eMenuState;
3519 					bEdit = pZoneClick->OnMouseClick(0);
3520 					return e;
3521 				}
3522 				else
3523 				{
3524 					pZoneClick->EmptyFunction();
3525 				}
3526 			}
3527 		}
3528 		else
3529 		{
3530 			if(!pZoneClick)
3531 			{
3532 				CMenuZone * iR = MenuAllZone.CheckZone(GInput->getMousePosAbs());
3533 
3534 				if(iR) {
3535 					pZoneClick=(CMenuElement*)iR;
3536 
3537 					if( GInput->getMouseButtonDoubleClick(Mouse::Button_0,300) )
3538 					{
3539 						bEdit = pZoneClick->OnMouseDoubleClick(0);
3540 
3541 						if(bEdit)
3542 							return pZoneClick->eMenuState;
3543 					}
3544 				}
3545 			}
3546 		}
3547 	}
3548 
3549 	//check les shortcuts
3550 	if(!bEdit)
3551 	{
3552 		iI=MenuAllZone.GetNbZone();
3553 
3554 		for(int iJ=0;iJ<iI;++iJ)
3555 		{
3556 			CMenuElement *pMenuElement=(CMenuElement*)MenuAllZone.GetZoneNum(iJ);
3557 			CMenuElement *CMenuElementShortCut = pMenuElement->OnShortCut();
3558 
3559 			if(CMenuElementShortCut)
3560 			{
3561 				pZoneClick=CMenuElementShortCut;
3562 				MENUSTATE e = pZoneClick->eMenuState;
3563 				bEdit = pZoneClick->OnMouseClick(0);
3564 				pZoneClick=CMenuElementShortCut;
3565 				return e;
3566 			}
3567 		}
3568 		}
3569 
3570 	return NOP;
3571 }
3572 
3573 //-----------------------------------------------------------------------------
3574 
UpdateGameKey(bool bEdit,CMenuElement * pmeElement,InputKeyId inputKeyId)3575 static bool UpdateGameKey(bool bEdit, CMenuElement *pmeElement, InputKeyId inputKeyId)
3576 {
3577 	bool bChange=false;
3578 
3579 	if(    (!bEdit)&&
3580 		(pmeElement) )
3581 	{
3582 		switch(pmeElement->iID)
3583 		{
3584 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_JUMP1:
3585 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_JUMP2:
3586 			bChange=config.setActionKey(CONTROLS_CUST_JUMP,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_JUMP1,inputKeyId);
3587 			break;
3588 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_MAGICMODE1:
3589 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_MAGICMODE2:
3590 			bChange=config.setActionKey(CONTROLS_CUST_MAGICMODE,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_MAGICMODE1,inputKeyId);
3591 			break;
3592 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_STEALTHMODE1:
3593 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_STEALTHMODE2:
3594 			bChange=config.setActionKey(CONTROLS_CUST_STEALTHMODE,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_STEALTHMODE1,inputKeyId);
3595 			break;
3596 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_WALKFORWARD1:
3597 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_WALKFORWARD2:
3598 			bChange=config.setActionKey(CONTROLS_CUST_WALKFORWARD,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_WALKFORWARD1,inputKeyId);
3599 			break;
3600 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_WALKBACKWARD1:
3601 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_WALKBACKWARD2:
3602 			bChange=config.setActionKey(CONTROLS_CUST_WALKBACKWARD,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_WALKBACKWARD1,inputKeyId);
3603 			break;
3604 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_STRAFELEFT1:
3605 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_STRAFELEFT2:
3606 			bChange=config.setActionKey(CONTROLS_CUST_STRAFELEFT,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_STRAFELEFT1,inputKeyId);
3607 			break;
3608 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_STRAFERIGHT1:
3609 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_STRAFERIGHT2:
3610 			bChange=config.setActionKey(CONTROLS_CUST_STRAFERIGHT,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_STRAFERIGHT1,inputKeyId);
3611 			break;
3612 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_LEANLEFT1:
3613 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_LEANLEFT2:
3614 			bChange=config.setActionKey(CONTROLS_CUST_LEANLEFT,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_LEANLEFT1,inputKeyId);
3615 			break;
3616 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_LEANRIGHT1:
3617 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_LEANRIGHT2:
3618 			bChange=config.setActionKey(CONTROLS_CUST_LEANRIGHT,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_LEANRIGHT1,inputKeyId);
3619 			break;
3620 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_CROUCH1:
3621 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_CROUCH2:
3622 			bChange=config.setActionKey(CONTROLS_CUST_CROUCH,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_CROUCH1,inputKeyId);
3623 			break;
3624 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_MOUSELOOK1:
3625 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_MOUSELOOK2:
3626 			bChange=config.setActionKey(CONTROLS_CUST_MOUSELOOK,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_MOUSELOOK1,inputKeyId);
3627 			break;
3628 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_ACTIONCOMBINE1:
3629 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_ACTIONCOMBINE2:
3630 			bChange=config.setActionKey(CONTROLS_CUST_ACTION,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_ACTIONCOMBINE1,inputKeyId);
3631 			break;
3632 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_INVENTORY1:
3633 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_INVENTORY2:
3634 			bChange=config.setActionKey(CONTROLS_CUST_INVENTORY,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_INVENTORY1,inputKeyId);
3635 			break;
3636 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOK1:
3637 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOK2:
3638 			bChange=config.setActionKey(CONTROLS_CUST_BOOK,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOK1,inputKeyId);
3639 			break;
3640 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKCHARSHEET1:
3641 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKCHARSHEET2:
3642 			bChange=config.setActionKey(CONTROLS_CUST_BOOKCHARSHEET,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKCHARSHEET1,inputKeyId);
3643 			break;
3644 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKSPELL1:
3645 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKSPELL2:
3646 			bChange=config.setActionKey(CONTROLS_CUST_BOOKSPELL,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKSPELL1,inputKeyId);
3647 			break;
3648 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKMAP1:
3649 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKMAP2:
3650 			bChange=config.setActionKey(CONTROLS_CUST_BOOKMAP,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKMAP1,inputKeyId);
3651 			break;
3652 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKQUEST1:
3653 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKQUEST2:
3654 			bChange=config.setActionKey(CONTROLS_CUST_BOOKQUEST,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_BOOKQUEST1,inputKeyId);
3655 			break;
3656 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_DRINKPOTIONLIFE1:
3657 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_DRINKPOTIONLIFE2:
3658 			bChange=config.setActionKey(CONTROLS_CUST_DRINKPOTIONLIFE,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_DRINKPOTIONLIFE1,inputKeyId);
3659 			break;
3660 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_DRINKPOTIONMANA1:
3661 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_DRINKPOTIONMANA2:
3662 			bChange=config.setActionKey(CONTROLS_CUST_DRINKPOTIONMANA,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_DRINKPOTIONMANA1,inputKeyId);
3663 			break;
3664 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_TORCH1:
3665 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_TORCH2:
3666 			bChange=config.setActionKey(CONTROLS_CUST_TORCH,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_TORCH1,inputKeyId);
3667 			break;
3668 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_CANCELCURSPELL1:
3669 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_CANCELCURSPELL2:
3670 			bChange=config.setActionKey(CONTROLS_CUST_CANCELCURSPELL,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_CANCELCURSPELL1,inputKeyId);
3671 			break;
3672 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_PRECAST1:
3673 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_PRECAST1_2:
3674 			bChange=config.setActionKey(CONTROLS_CUST_PRECAST1,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_PRECAST1,inputKeyId);
3675 			break;
3676 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_PRECAST2:
3677 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_PRECAST2_2:
3678 			bChange=config.setActionKey(CONTROLS_CUST_PRECAST2,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_PRECAST2,inputKeyId);
3679 			break;
3680 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_PRECAST3:
3681 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_PRECAST3_2:
3682 			bChange=config.setActionKey(CONTROLS_CUST_PRECAST3,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_PRECAST3,inputKeyId);
3683 			break;
3684 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_WEAPON1:
3685 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_WEAPON2:
3686 			bChange=config.setActionKey(CONTROLS_CUST_WEAPON,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_WEAPON1,inputKeyId);
3687 			break;
3688 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_QUICKLOAD:
3689 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_QUICKLOAD2:
3690 			bChange=config.setActionKey(CONTROLS_CUST_QUICKLOAD,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_QUICKLOAD,inputKeyId);
3691 			break;
3692 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_QUICKSAVE:
3693 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_QUICKSAVE2:
3694 			bChange=config.setActionKey(CONTROLS_CUST_QUICKSAVE,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_QUICKSAVE,inputKeyId);
3695 			break;
3696 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_TURNLEFT1:
3697 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_TURNLEFT2:
3698 			bChange=config.setActionKey(CONTROLS_CUST_TURNLEFT,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_TURNLEFT1,inputKeyId);
3699 			break;
3700 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_TURNRIGHT1:
3701 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_TURNRIGHT2:
3702 			bChange=config.setActionKey(CONTROLS_CUST_TURNRIGHT,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_TURNRIGHT1,inputKeyId);
3703 			break;
3704 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_LOOKUP1:
3705 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_LOOKUP2:
3706 			bChange=config.setActionKey(CONTROLS_CUST_LOOKUP,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_LOOKUP1,inputKeyId);
3707 			break;
3708 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_LOOKDOWN1:
3709 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_LOOKDOWN2:
3710 			bChange=config.setActionKey(CONTROLS_CUST_LOOKDOWN,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_LOOKDOWN1,inputKeyId);
3711 			break;
3712 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_STRAFE1:
3713 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_STRAFE2:
3714 			bChange=config.setActionKey(CONTROLS_CUST_STRAFE,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_STRAFE1,inputKeyId);
3715 			break;
3716 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_CENTERVIEW1:
3717 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_CENTERVIEW2:
3718 			bChange=config.setActionKey(CONTROLS_CUST_CENTERVIEW,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_CENTERVIEW1,inputKeyId);
3719 			break;
3720 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_FREELOOK1:
3721 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_FREELOOK2:
3722 			bChange=config.setActionKey(CONTROLS_CUST_FREELOOK,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_FREELOOK1,inputKeyId);
3723 			break;
3724 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_PREVIOUS1:
3725 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_PREVIOUS2:
3726 			bChange=config.setActionKey(CONTROLS_CUST_PREVIOUS,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_PREVIOUS1,inputKeyId);
3727 			break;
3728 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_NEXT1:
3729 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_NEXT2:
3730 			bChange=config.setActionKey(CONTROLS_CUST_NEXT,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_NEXT1,inputKeyId);
3731 			break;
3732 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_CROUCHTOGGLE1:
3733 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_CROUCHTOGGLE2:
3734 			bChange=config.setActionKey(CONTROLS_CUST_CROUCHTOGGLE,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_CROUCHTOGGLE1,inputKeyId);
3735 			break;
3736 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_UNEQUIPWEAPON1:
3737 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_UNEQUIPWEAPON2:
3738 			bChange=config.setActionKey(CONTROLS_CUST_UNEQUIPWEAPON,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_UNEQUIPWEAPON1,inputKeyId);
3739 			break;
3740 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_MINIMAP1:
3741 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_MINIMAP2:
3742 			bChange=config.setActionKey(CONTROLS_CUST_MINIMAP,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_MINIMAP1,inputKeyId);
3743 			break;
3744 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_TOGGLE_FULLSCREEN1:
3745 		case BUTTON_MENUOPTIONS_CONTROLS_CUST_TOGGLE_FULLSCREEN2:
3746 			bChange=config.setActionKey(CONTROLS_CUST_TOGGLE_FULLSCREEN,pmeElement->iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_TOGGLE_FULLSCREEN1,inputKeyId);
3747 			break;
3748 		}
3749 	}
3750 
3751 	return bChange;
3752 }
3753 
3754 //-----------------------------------------------------------------------------
3755 
Render()3756 int CWindowMenuConsole::Render()
3757 {
3758 	if(bNoMenu) return 0;
3759 
3760 	int iSlider=0;
3761 
3762 	//------------------------------------------------------------------------
3763 	// Console display
3764 	GRenderer->SetRenderState(Renderer::AlphaBlending, true);
3765 	GRenderer->SetBlendFunc(Renderer::BlendZero, Renderer::BlendInvSrcColor);
3766 	GRenderer->SetRenderState(Renderer::DepthTest, false);
3767 
3768 	EERIEDrawBitmap2(static_cast<float>(iPosX), static_cast<float>(iSavePosY),
3769 	                 RATIO_X(pTexBackground->m_dwWidth), RATIO_Y(pTexBackground->m_dwHeight),
3770 	                 0, pTexBackground, Color::white);
3771 
3772 	GRenderer->SetRenderState(Renderer::DepthTest, true);
3773 	GRenderer->SetBlendFunc(Renderer::BlendOne, Renderer::BlendOne);
3774 	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
3775 
3776 	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
3777 	EERIEDrawBitmap2(static_cast<float>(iPosX), static_cast<float>(iSavePosY),
3778 	                 RATIO_X(pTexBackgroundBorder->m_dwWidth), RATIO_Y(pTexBackgroundBorder->m_dwHeight),
3779 	                 0, pTexBackgroundBorder, Color::white);
3780 
3781 	//------------------------------------------------------------------------
3782 
3783 	int t = MenuAllZone.GetNbZone();
3784 
3785 	int iARXDiffTimeMenu  = checked_range_cast<int>(ARXDiffTimeMenu);
3786 
3787 	for(int i=0;i<t;++i)
3788 	{
3789 		CMenuElement *pMe=(CMenuElement*)MenuAllZone.GetZoneNum(i);
3790 
3791 		if(pMe->bActif)
3792 		{
3793 			pMe->Update(iARXDiffTimeMenu);
3794 			pMe->Render();
3795 		}
3796 		else
3797 		{
3798 			iSlider++;
3799 		}
3800 	}
3801 
3802 	//HIGHLIGHT
3803 	if(pZoneClick && pZoneClick->bActif)
3804 	{
3805 		bool bReInit=false;
3806 
3807 		pZoneClick->RenderMouseOver();
3808 
3809 		switch(pZoneClick->eState)
3810 		{
3811 		case EDIT_TIME:
3812 			UpdateText();
3813 			break;
3814 		case GETTOUCH_TIME:
3815 			{
3816 				if(bFrameOdd)
3817 					((CMenuElementText*)pZoneClick)->lColorHighlight = Color(255, 0, 0);
3818 				else
3819 					((CMenuElementText*)pZoneClick)->lColorHighlight = Color(50, 0, 0);
3820 
3821 				bool keyTouched = GInput->isAnyKeyPressed();
3822 				int keyId = GInput->getKeyPressed();
3823 
3824 				if( GInput->isKeyPressed(Keyboard::Key_LeftShift)||
3825 					GInput->isKeyPressed(Keyboard::Key_RightShift)||
3826 					GInput->isKeyPressed(Keyboard::Key_LeftCtrl)||
3827 					GInput->isKeyPressed(Keyboard::Key_RightCtrl)||
3828 					GInput->isKeyPressed(Keyboard::Key_LeftAlt)||
3829 					GInput->isKeyPressed(Keyboard::Key_RightAlt) )
3830 				{
3831 					if(!((keyId & INPUT_COMBINATION_MASK )>>16))
3832 						keyTouched = false;
3833 				}
3834 				else
3835 				{
3836 					if(GInput->isKeyPressedNowUnPressed(Keyboard::Key_LeftShift))
3837 					{
3838 						keyTouched = true;
3839 						keyId = Keyboard::Key_LeftShift;
3840 					}
3841 
3842 					if(GInput->isKeyPressedNowUnPressed(Keyboard::Key_RightShift))
3843 					{
3844 						keyTouched = true;
3845 						keyId = Keyboard::Key_RightShift;
3846 					}
3847 
3848 					if(GInput->isKeyPressedNowUnPressed(Keyboard::Key_LeftCtrl))
3849 					{
3850 						keyTouched = true;
3851 						keyId = Keyboard::Key_LeftCtrl;
3852 					}
3853 
3854 					if(GInput->isKeyPressedNowUnPressed(Keyboard::Key_RightCtrl))
3855 					{
3856 						keyTouched = true;
3857 						keyId = Keyboard::Key_RightCtrl;
3858 					}
3859 
3860 					if(GInput->isKeyPressedNowUnPressed(Keyboard::Key_LeftAlt))
3861 					{
3862 						keyTouched = true;
3863 						keyId = Keyboard::Key_LeftAlt;
3864 					}
3865 
3866 					if(GInput->isKeyPressedNowUnPressed(Keyboard::Key_RightAlt))
3867 					{
3868 						keyTouched = true;
3869 						keyId = Keyboard::Key_RightAlt;
3870 					}
3871 				}
3872 
3873 				InputKeyId inputKeyId;
3874 				CMenuElement *pmeElement = GetTouch(keyTouched, keyId, &inputKeyId, true);
3875 
3876 				if(pmeElement)
3877 				{
3878 					if(UpdateGameKey(bEdit,pmeElement, inputKeyId))
3879 					{
3880 						bReInit=true;
3881 					}
3882 				}
3883 			}
3884 			break;
3885 		default:
3886 			{
3887 				if(GInput->getMouseButtonNowPressed(Mouse::Button_0))
3888 				{
3889 					CMenuZone *pmzMenuZone = MenuAllZone.GetZoneWithID(BUTTON_MENUOPTIONS_CONTROLS_CUST_DEFAULT);
3890 
3891 					if(pmzMenuZone==pZoneClick)
3892 					{
3893 						config.setDefaultActionKeys();
3894 						bReInit=true;
3895 					}
3896 				}
3897 			}
3898 			break;
3899 		}
3900 
3901 		if(bReInit)
3902 		{
3903 			ReInitActionKey();
3904 			bMouseAttack=false;
3905 		}
3906 	}
3907 
3908 	//DEBUG ZONE
3909 	MenuAllZone.DrawZone();
3910 
3911 	return iSlider;
3912 }
3913 
ReInitActionKey()3914 void CWindowMenuConsole::ReInitActionKey()
3915 {
3916 	int iID=BUTTON_MENUOPTIONS_CONTROLS_CUST_JUMP1;
3917 	int iI=NUM_ACTION_KEY;
3918 
3919 	while(iI--)
3920 	{
3921 		int iTab=(iID-BUTTON_MENUOPTIONS_CONTROLS_CUST_JUMP1)>>1;
3922 
3923 		CMenuZone *pmzMenuZone = MenuAllZone.GetZoneWithID(iID);
3924 
3925 		if (pmzMenuZone)
3926 		{
3927 			if(pmzMenuZone)
3928 			{
3929 				pZoneClick = (CMenuElement*)pmzMenuZone;
3930 				GetTouch(true, config.actions[iTab].key[0]);
3931 			}
3932 
3933 			pmzMenuZone = MenuAllZone.GetZoneWithID(iID+1);
3934 
3935 			if( pmzMenuZone )
3936 			{
3937 				pZoneClick = (CMenuElement*)pmzMenuZone;
3938 				GetTouch(true, config.actions[iTab].key[1]);
3939 			}
3940 		}
3941 
3942 		iID+=2;
3943 	}
3944 }
3945 
3946 //-----------------------------------------------------------------------------
3947 
CMenuPanel()3948 CMenuPanel::CMenuPanel()
3949 : CMenuElement(NOP)
3950 {
3951 	vElement.clear();
3952 
3953 	pRef = this;
3954 }
3955 
3956 //-----------------------------------------------------------------------------
3957 
~CMenuPanel()3958 CMenuPanel::~CMenuPanel()
3959 {
3960 	for (std::vector<CMenuElement*>::iterator it = vElement.begin(), it_end = vElement.end(); it != it_end; ++it)
3961 		delete (*it);
3962 }
3963 
3964 //-----------------------------------------------------------------------------
3965 
Move(int _iX,int _iY)3966 void CMenuPanel::Move(int _iX, int _iY)
3967 {
3968 	rZone.left += _iX;
3969 	rZone.top += _iY;
3970 	rZone.right += _iX;
3971 	rZone.bottom += _iY;
3972 
3973 	for (std::vector<CMenuElement*>::iterator it = vElement.begin(), it_end = vElement.end(); it != it_end; ++it)
3974 		(*it)->Move(_iX, _iY);
3975 }
3976 
3977 //-----------------------------------------------------------------------------
3978 // patch on ajoute à droite en ligne
AddElement(CMenuElement * _pElem)3979 void CMenuPanel::AddElement(CMenuElement* _pElem)
3980 {
3981 	vElement.push_back(_pElem);
3982 
3983 	if (vElement.size() == 1)
3984 		rZone = _pElem->rZone;
3985 	else
3986 	{
3987 		rZone.left = std::min(rZone.left, _pElem->rZone.left);
3988 		rZone.top = std::min(rZone.top, _pElem->rZone.top);
3989 	}
3990 
3991 	// + taille elem
3992 	rZone.right = std::max(rZone.right, _pElem->rZone.right);
3993 	rZone.bottom = std::max(rZone.bottom, _pElem->rZone.bottom);
3994 
3995 	_pElem->Move(0, ((GetHeight() - _pElem->rZone.bottom) / 2));
3996 }
3997 
3998 //-----------------------------------------------------------------------------
3999 // patch on ajoute à droite en ligne
AddElementNoCenterIn(CMenuElement * _pElem)4000 void CMenuPanel::AddElementNoCenterIn(CMenuElement* _pElem)
4001 {
4002 	vElement.push_back(_pElem);
4003 
4004 	if (vElement.size() == 1)
4005 		rZone=_pElem->rZone;
4006 	else
4007 	{
4008 		rZone.left = std::min(rZone.left, _pElem->rZone.left);
4009 		rZone.top = std::min(rZone.top, _pElem->rZone.top);
4010 	}
4011 
4012 	// + taille elem
4013 	rZone.right = std::max(rZone.right, _pElem->rZone.right);
4014 	rZone.bottom = std::max(rZone.bottom, _pElem->rZone.bottom);
4015 
4016 }
4017 
4018 //-----------------------------------------------------------------------------
4019 
OnShortCut()4020 CMenuElement* CMenuPanel::OnShortCut()
4021 {
4022 	for (std::vector<CMenuElement*>::iterator it = vElement.begin(), it_end = vElement.end(); it != it_end; ++it)
4023 		if ((*it)->OnShortCut())
4024 			return *it;
4025 
4026 	return NULL;
4027 }
4028 
4029 //-----------------------------------------------------------------------------
4030 
Update(int _iTime)4031 void CMenuPanel::Update(int _iTime)
4032 {
4033 	rZone.right = rZone.left;
4034 	rZone.bottom = rZone.top;
4035 
4036 	;
4037 
4038 	for (std::vector<CMenuElement*>::iterator it = vElement.begin(), it_end = vElement.end(); it != it_end; ++it)
4039 	{
4040 		(*it)->Update(_iTime);
4041 		rZone.right = std::max(rZone.right, (*it)->rZone.right);
4042 		rZone.bottom = std::max(rZone.bottom, (*it)->rZone.bottom);
4043 	}
4044 }
4045 
4046 //-----------------------------------------------------------------------------
4047 
Render()4048 void CMenuPanel::Render()
4049 {
4050 	if(bNoMenu) return;
4051 
4052 	for (std::vector<CMenuElement*>::iterator it = vElement.begin(), it_end = vElement.end(); it != it_end; ++it)
4053 		(*it)->Render();
4054 }
4055 
4056 //-----------------------------------------------------------------------------
4057 
GetZoneWithID(int _iID)4058 CMenuZone * CMenuPanel::GetZoneWithID(int _iID)
4059 {
4060 	for (std::vector<CMenuElement*>::iterator it = vElement.begin(), it_end = vElement.end(); it != it_end; ++it)
4061 		if (CMenuZone* pZone = (*it)->GetZoneWithID(_iID))
4062 			return pZone;
4063 
4064 	return NULL;
4065 }
4066 
4067 //-----------------------------------------------------------------------------
4068 
IsMouseOver(const Vec2s & mousePos) const4069 CMenuZone * CMenuPanel::IsMouseOver(const Vec2s& mousePos) const
4070 {
4071 	if ((mousePos.x >= rZone.left) &&
4072 		(mousePos.y >= rZone.top) &&
4073 		(mousePos.x <= rZone.right) &&
4074 		(mousePos.y <= rZone.bottom))
4075 	{
4076 		vector<CMenuElement *>::const_iterator i;
4077 
4078 		for(i=vElement.begin();i!=vElement.end();++i)
4079 		{
4080 			if ((*i)->bCheck &&
4081 				(*i)->bActif &&
4082 				(mousePos.x >= (*i)->rZone.left) &&
4083 				(mousePos.y >= (*i)->rZone.top) &&
4084 				(mousePos.x <= (*i)->rZone.right) &&
4085 				(mousePos.y <= (*i)->rZone.bottom))
4086 				return (*i)->pRef;
4087 		}
4088 	}
4089 
4090 	return NULL;
4091 }
4092 
4093 //-----------------------------------------------------------------------------
4094 
CMenuButton(int _iID,Font * _pFont,MENUSTATE _eMenuState,int _iPosX,int _iPosY,const std::string & _pText,float _fSize,TextureContainer * _pTex,TextureContainer * _pTexOver,int _iColor)4095 CMenuButton::CMenuButton(int _iID, Font* _pFont,MENUSTATE _eMenuState,int _iPosX,int _iPosY, const std::string& _pText,float _fSize,TextureContainer *_pTex,TextureContainer *_pTexOver,int _iColor)
4096 	: CMenuElement(_eMenuState)
4097 {
4098 	iID = _iID;
4099 	pFont = _pFont;
4100 	fSize=_fSize;
4101 
4102 	rZone.left=_iPosX;
4103 	rZone.top=_iPosY;
4104 	rZone.right  = rZone.left ;
4105 	rZone.bottom = rZone.top ;
4106 
4107 	vText.clear();
4108 	iPos=0;
4109 
4110 	if( !_pText.empty() )
4111 	{
4112 		AddText(_pText);
4113 	}
4114 
4115 	pTex=_pTex;
4116 	pTexOver=_pTexOver;
4117 
4118 
4119 	if(pTex) {
4120 		float rZoneR = rZone.left + RATIO_X(pTex->m_dwWidth);
4121 		float rZoneB = rZone.top + RATIO_Y(pTex->m_dwHeight);
4122 		rZone.right  = max(rZone.right,  checked_range_cast<Rect::Num>(rZoneR));
4123 		rZone.bottom = max(rZone.bottom, checked_range_cast<Rect::Num>(rZoneB));
4124 	}
4125 
4126 	if(pTexOver) {
4127 		float rZoneR = rZone.left + RATIO_X(pTexOver->m_dwWidth);
4128 		float rZoneB = rZone.top + RATIO_Y(pTexOver->m_dwHeight);
4129 		rZone.right  = max(rZone.right, checked_range_cast<Rect::Num>(rZoneR));
4130 		rZone.bottom = max(rZone.bottom, checked_range_cast<Rect::Num>(rZoneB));
4131 	}
4132 
4133 	iColor=_iColor;
4134 
4135 	pRef=this;
4136 }
4137 
4138 //-----------------------------------------------------------------------------
4139 
~CMenuButton()4140 CMenuButton::~CMenuButton() {
4141 }
4142 
4143 //-----------------------------------------------------------------------------
4144 
SetPos(float _iX,float _iY)4145 void CMenuButton::SetPos(float _iX,float _iY)
4146 {
4147 	CMenuZone::SetPos(_iX, _iY);
4148 
4149 	int iWidth = 0;
4150 	int iHeight = 0;
4151 	if(pTex) {
4152 		iWidth = checked_range_cast<int>(RATIO_X(pTex->m_dwWidth));
4153 		iHeight = checked_range_cast<int>(RATIO_Y(pTex->m_dwHeight));
4154 	}
4155 
4156 	int iWidth2 = 0;
4157 	int iHeight2 = 0;
4158 	if(pTexOver) {
4159 		iWidth2 = checked_range_cast<int>(RATIO_X(pTexOver->m_dwWidth));
4160 		iHeight2 = checked_range_cast<int>(RATIO_Y(pTexOver->m_dwHeight));
4161 	}
4162 
4163 	rZone.right = static_cast<int>(_iX) + max(iWidth, iWidth2);
4164 	rZone.bottom = static_cast<int>(_iY) + max(iHeight, iHeight2);
4165 }
4166 
4167 //-----------------------------------------------------------------------------
4168 
AddText(const std::string & _pText)4169 void CMenuButton::AddText( const std::string& _pText)
4170 {
4171 	if ( _pText.empty() )
4172 		return;
4173 
4174 	vText += _pText;
4175 
4176 	int iSizeXButton=rZone.right-rZone.left;
4177 	int iSizeYButton=rZone.bottom-rZone.top;
4178 
4179 	Vec2i textSize = pFont->getTextSize(_pText);
4180 
4181 	if(textSize.x>iSizeXButton) iSizeXButton=textSize.x;
4182 	if(textSize.y>iSizeYButton) iSizeYButton=textSize.y;
4183 
4184 	rZone.right=rZone.left+iSizeXButton;
4185 	rZone.bottom=rZone.top+iSizeYButton;
4186 }
4187 
OnMouseClick(int _iMouseButton)4188 bool CMenuButton::OnMouseClick(int _iMouseButton) {
4189 
4190 	(void)_iMouseButton;
4191 
4192 	if(!enabled) {
4193 		return false;
4194 	}
4195 
4196 	iPos++;
4197 
4198 	arx_assert(iPos >= 0);
4199 
4200 	if((size_t)iPos >= vText.size() )
4201 		iPos = 0;
4202 
4203 	ARX_SOUND_PlayMenu(SND_MENU_CLICK);
4204 
4205 	return false;
4206 }
4207 
4208 //-----------------------------------------------------------------------------
4209 
Update(int _iDTime)4210 void CMenuButton::Update(int _iDTime) {
4211 	(void)_iDTime;
4212 }
4213 
4214 //-----------------------------------------------------------------------------
4215 
Render()4216 void CMenuButton::Render()
4217 {
4218 	if(bNoMenu) return;
4219 
4220 	//affichage de la texture
4221 	if(pTex) {
4222 		EERIEDrawBitmap2(static_cast<float>(rZone.left), static_cast<float>(rZone.top),
4223 		                 RATIO_X(pTex->m_dwWidth), RATIO_Y(pTex->m_dwHeight), 0, pTex, Color::white);
4224 	}
4225 
4226 	//affichage de la font
4227 	if(vText.size())
4228 	{
4229 		char pText = vText[iPos];
4230 
4231 		GRenderer->SetRenderState(Renderer::AlphaBlending, true);
4232 		GRenderer->SetBlendFunc(Renderer::BlendOne, Renderer::BlendOne);
4233 
4234 		Vec3f ePos;
4235 		ePos.x = (float)rZone.left;
4236 		ePos.y = (float)rZone.top;
4237 		ePos.z = 1;
4238 
4239 		FontRenderText(pFont, ePos, &pText, Color(232, 204, 142));
4240 
4241 		GRenderer->SetRenderState(Renderer::AlphaBlending, false);
4242 	}
4243 }
4244 
4245 //-----------------------------------------------------------------------------
4246 
RenderMouseOver()4247 void CMenuButton::RenderMouseOver()
4248 {
4249 	if(bNoMenu) return;
4250 
4251 	pMenuCursor->SetMouseOver();
4252 
4253 	//affichage de la texture
4254 	if(pTexOver)
4255 	{
4256 		TexturedVertex v[4];
4257 		v[0].color = v[1].color = v[2].color = v[3].color = Color::white.toBGR();
4258 		v[0].p.z=v[1].p.z=v[2].p.z=v[3].p.z=0.f;
4259 		v[0].rhw=v[1].rhw=v[2].rhw=v[3].rhw=0.999999f;
4260 
4261 		GRenderer->SetTexture(0, pTexOver);
4262 		v[0].p.x = (float)rZone.left;
4263 		v[0].p.y = (float)rZone.top;
4264 		v[0].uv.x = 0.f;
4265 		v[0].uv.y = 0.f;
4266 		v[1].p.x = (float)(rZone.right);
4267 		v[1].p.y = v[0].p.y;
4268 		v[1].uv.x = 0.999999f;
4269 		v[1].uv.y = 0.f;
4270 		v[2].p.x = v[0].p.x;
4271 		v[2].p.y = (float)(rZone.bottom);
4272 		v[2].uv.x = 0.f;
4273 		v[2].uv.y = 0.999999f;
4274 		v[3].p.x = v[1].p.x;
4275 		v[3].p.y = v[2].p.y;
4276 		v[3].uv.x = 0.999999f;
4277 		v[3].uv.y = 0.999999f;
4278 		EERIEDRAWPRIM(Renderer::TriangleStrip, v, 4);
4279 	}
4280 
4281 	if( vText.size() )
4282 	{
4283 		char pText=vText[iPos];
4284 
4285 		GRenderer->SetRenderState(Renderer::AlphaBlending, true);
4286 		GRenderer->SetBlendFunc(Renderer::BlendOne, Renderer::BlendOne);
4287 
4288 		Vec3f ePos;
4289 		ePos.x = (float)rZone.left;
4290 		ePos.y = (float)rZone.top;
4291 		ePos.z = 1;
4292 
4293 		FontRenderText(pFont, ePos, &pText, Color(255, 255, 255));
4294 
4295 		GRenderer->SetRenderState(Renderer::AlphaBlending, false);
4296 	}
4297 }
4298 
4299 //-----------------------------------------------------------------------------
4300 
CMenuSliderText(int _iID,int _iPosX,int _iPosY)4301 CMenuSliderText::CMenuSliderText(int _iID, int _iPosX, int _iPosY)
4302 	: CMenuElement(NOP)
4303 {
4304 	iID = _iID;
4305 	TextureContainer *pTex = TextureContainer::Load("graph/interface/menus/menu_slider_button_left");
4306 	pLeftButton = new CMenuButton(-1, hFontMenu, NOP, _iPosX, _iPosY, string(), 1, pTex, pTex, -1);
4307 	pTex = TextureContainer::Load("graph/interface/menus/menu_slider_button_right");
4308 	pRightButton = new CMenuButton(-1, hFontMenu, NOP, _iPosX, _iPosY, string(), 1, pTex, pTex, -1);
4309 
4310 	vText.clear();
4311 
4312 	iPos = 0;
4313 	iOldPos = -1;
4314 
4315 	rZone.left   = _iPosX;
4316 	rZone.top    = _iPosY;
4317 	rZone.right  = _iPosX + pLeftButton->GetWidth() + pRightButton->GetWidth();
4318 	rZone.bottom = _iPosY + max(pLeftButton->GetHeight(), pRightButton->GetHeight());
4319 
4320 	pRef = this;
4321 }
4322 
~CMenuSliderText()4323 CMenuSliderText::~CMenuSliderText() {
4324 	delete pLeftButton;
4325 	delete pRightButton;
4326 	BOOST_FOREACH(CMenuElementText * e, vText) {
4327 		delete e;
4328 	}
4329 }
4330 
SetWidth(int _iWidth)4331 void CMenuSliderText::SetWidth(int _iWidth) {
4332 
4333 	rZone.right  = max(rZone.right, rZone.left +  _iWidth);
4334 	pRightButton->SetPos(rZone.right - pRightButton->GetWidth(), pRightButton->rZone.top);
4335 
4336 	int dx=rZone.right-rZone.left-pLeftButton->GetWidth()-pRightButton->GetWidth();
4337 	//on recentre tout
4338 	vector<CMenuElementText*>::iterator it;
4339 
4340 	for(it=vText.begin();it<vText.end();++it)
4341 	{
4342 		CMenuElementText *pMenuElementText=*it;
4343 		Vec2i textSize = pMenuElementText->GetTextSize();
4344 
4345 		int dxx=(dx-textSize.x)>>1;
4346 		pMenuElementText->SetPos(static_cast<float>(pLeftButton->rZone.right + dxx), static_cast<float>(rZone.top));
4347 	}
4348 }
4349 
4350 //-----------------------------------------------------------------------------
4351 
AddText(CMenuElementText * _pText)4352 void CMenuSliderText::AddText(CMenuElementText *_pText)
4353 {
4354 
4355 	_pText->setEnabled(enabled);
4356 
4357 	_pText->Move(rZone.left + pLeftButton->GetWidth(), rZone.top + 0);
4358 	vText.push_back(_pText);
4359 
4360 	Vec2i textSize = _pText->GetTextSize();
4361 
4362 	rZone.right  = max(rZone.right, rZone.left + pLeftButton->GetWidth() + pRightButton->GetWidth() + textSize.x);
4363 	rZone.bottom = max(rZone.bottom, rZone.top + textSize.y);
4364 
4365 	pLeftButton->SetPos(rZone.left, rZone.top+(textSize.y>>2));
4366 	pRightButton->SetPos(rZone.right-pRightButton->GetWidth(), rZone.top+(textSize.y>>2));
4367 
4368 	int dx=rZone.right-rZone.left-pLeftButton->GetWidth()-pRightButton->GetWidth();
4369 	//on recentre tout
4370 	vector<CMenuElementText*>::iterator it;
4371 
4372 	for(it=vText.begin();it<vText.end();++it)
4373 	{
4374 		CMenuElementText *pMenuElementText=*it;
4375 
4376 		textSize = pMenuElementText->GetTextSize();
4377 
4378 		int dxx=(dx-textSize.x)>>1;
4379 		pMenuElementText->SetPos(static_cast<float>(pLeftButton->rZone.right + dxx), static_cast<float>(rZone.top));
4380 	}
4381 }
4382 
4383 //-----------------------------------------------------------------------------
4384 
Move(int _iX,int _iY)4385 void CMenuSliderText::Move(int _iX, int _iY)
4386 {
4387 	CMenuZone::Move(_iX, _iY);
4388 
4389 	pLeftButton->Move(_iX, _iY);
4390 	pRightButton->Move(_iX, _iY);
4391 
4392 	for (std::vector<CMenuElementText*>::const_iterator i = vText.begin(), i_end = vText.end(); i != i_end; ++i)
4393 		(*i)->Move(_iX, _iY);
4394 }
4395 
4396 //-----------------------------------------------------------------------------
4397 
EmptyFunction()4398 void CMenuSliderText::EmptyFunction()
4399 {
4400 	//Touche pour la selection
4401 	if(GInput->isKeyPressedNowPressed(Keyboard::Key_LeftArrow))
4402 	{
4403 		iPos--;
4404 
4405 		if (iPos <= 0) iPos = 0;
4406 	}
4407 	else
4408 	{
4409 		if( GInput->isKeyPressedNowPressed( Keyboard::Key_RightArrow ) )
4410 		{
4411 			iPos++;
4412 
4413 			arx_assert(iPos >= 0);
4414 
4415 			if ((size_t)iPos >= vText.size() - 1 ) iPos = vText.size() - 1;
4416 
4417 
4418 		}
4419 	}
4420 }
4421 
4422 //-----------------------------------------------------------------------------
4423 
OnMouseClick(int)4424 bool CMenuSliderText::OnMouseClick(int)
4425 {
4426 	if(!enabled) {
4427 		return false;
4428 	}
4429 
4430 	ARX_SOUND_PlayMenu(SND_MENU_CLICK);
4431 
4432 	if(iOldPos<0)
4433 		iOldPos=iPos;
4434 
4435 	int iX = GInput->getMousePosAbs().x;
4436 	int iY = GInput->getMousePosAbs().y;
4437 
4438 	if ((iX >= rZone.left) &&
4439 		(iY >= rZone.top) &&
4440 		(iX <= rZone.right) &&
4441 		(iY <= rZone.bottom))
4442 	{
4443 		if ((iX >= pLeftButton->rZone.left) &&
4444 			(iY >= pLeftButton->rZone.top) &&
4445 			(iX <= pLeftButton->rZone.right) &&
4446 			(iY <= pLeftButton->rZone.bottom))
4447 		{
4448 			iPos--;
4449 
4450 			if(iPos < 0) {
4451 				iPos = vText.size() - 1;
4452 			}
4453 		}
4454 		else if ((iX >= pRightButton->rZone.left) &&
4455 				(iY >= pRightButton->rZone.top) &&
4456 				(iX <= pRightButton->rZone.right) &&
4457 				(iY <= pRightButton->rZone.bottom))
4458 		{
4459 			iPos++;
4460 
4461 			arx_assert(iPos >= 0);
4462 
4463 			if(size_t(iPos) >= vText.size()) {
4464 				iPos = 0;
4465 			}
4466 		}
4467 	}
4468 
4469 	switch(iID) {
4470 
4471 		case BUTTON_MENUOPTIONSVIDEO_RESOLUTION: {
4472 			std::string pcText = (vText.at(iPos))->lpszText;
4473 
4474 			if(pcText == AUTO_RESOLUTION_STRING) {
4475 
4476 				newWidth = newHeight = 0;
4477 
4478 			} else {
4479 
4480 				std::stringstream ss( pcText );
4481 				int iX = config.video.resolution.x;
4482 				int iY = config.video.resolution.y;
4483 				char tmp;
4484 				ss >> iX >> tmp >> iY;
4485 				newWidth = iX;
4486 				newHeight = iY;
4487 
4488 			}
4489 
4490 			break;
4491 		}
4492 
4493 		case BUTTON_MENUOPTIONSVIDEO_RENDERER: {
4494 			switch((vText.at(iPos))->eMenuState) {
4495 				case OPTIONS_VIDEO_RENDERER_OPENGL:    config.window.framework = "SDL"; break;
4496 				case OPTIONS_VIDEO_RENDERER_D3D9:      config.window.framework = "D3D9"; break;
4497 				case OPTIONS_VIDEO_RENDERER_AUTOMATIC: config.window.framework = "auto"; break;
4498 				default: break;
4499 			}
4500 			break;
4501 		}
4502 
4503 		case BUTTON_MENUOPTIONSAUDIO_BACKEND: {
4504 			switch((vText.at(iPos))->eMenuState) {
4505 				case OPTIONS_AUDIO_BACKEND_OPENAL:    config.audio.backend = "OpenAL"; break;
4506 				case OPTIONS_AUDIO_BACKEND_DSOUND:    config.audio.backend = "DirectSound"; break;
4507 				case OPTIONS_AUDIO_BACKEND_AUTOMATIC: config.audio.backend = "auto"; break;
4508 				default: break;
4509 			}
4510 			break;
4511 		}
4512 		case BUTTON_MENUOPTIONS_CONTROLS_BACKEND: {
4513 			switch((vText.at(iPos))->eMenuState) {
4514 				case OPTIONS_INPUT_BACKEND_SDL:       config.input.backend = "SDL"; break;
4515 				case OPTIONS_INPUT_BACKEND_DINPUT:    config.input.backend = "DirectInput8"; break;
4516 				case OPTIONS_INPUT_BACKEND_AUTOMATIC: config.input.backend = "auto"; break;
4517 				default: break;
4518 			}
4519 			break;
4520 		}
4521 
4522 		// MENUOPTIONS_VIDEO
4523 		case BUTTON_MENUOPTIONSVIDEO_BPP: {
4524 			std::stringstream ss;
4525 			ss << vText[iPos]->lpszText;
4526 			ss >> newBpp;
4527 			break;
4528 		}
4529 
4530 		case BUTTON_MENUOPTIONSVIDEO_OTHERSDETAILS: {
4531 			ARXMenu_Options_Video_SetDetailsQuality(iPos);
4532 			break;
4533 		}
4534 
4535 	}
4536 
4537 	return false;
4538 }
4539 
4540 //-----------------------------------------------------------------------------
4541 
Update(int _iTime)4542 void CMenuSliderText::Update(int _iTime)
4543 {
4544 	pLeftButton->Update(_iTime);
4545 	pRightButton->Update(_iTime);
4546 }
4547 
4548 //-----------------------------------------------------------------------------
4549 
Render()4550 void CMenuSliderText::Render() {
4551 
4552 	if(bNoMenu) return;
4553 
4554 	if(enabled) {
4555 		pLeftButton->Render();
4556 		pRightButton->Render();
4557 	}
4558 
4559 	if(iPos >= 0 && size_t(iPos) < vText.size() && vText[iPos]) {
4560 		GRenderer->SetRenderState(Renderer::AlphaBlending, false);
4561 		vText[iPos]->Render();
4562 		GRenderer->SetRenderState(Renderer::AlphaBlending, false);
4563 	}
4564 }
4565 
setEnabled(bool enable)4566 void CMenuSliderText::setEnabled(bool enable) {
4567 	CMenuElement::setEnabled(enable);
4568 	pLeftButton->setEnabled(enable);
4569 	pRightButton->setEnabled(enable);
4570 	for(size_t i = 0; i < vText.size(); i++) {
4571 		vText[i]->setEnabled(enable);
4572 	}
4573 }
4574 
4575 //-----------------------------------------------------------------------------
4576 
RenderMouseOver()4577 void CMenuSliderText::RenderMouseOver()
4578 {
4579 	if(bNoMenu) return;
4580 
4581 	pMenuCursor->SetMouseOver();
4582 
4583 	int iX = GInput->getMousePosAbs().x;
4584 	int iY = GInput->getMousePosAbs().y;
4585 
4586 	if(!enabled) {
4587 		return;
4588 	}
4589 
4590 	GRenderer->SetRenderState(Renderer::AlphaBlending, true);
4591 	GRenderer->SetBlendFunc(Renderer::BlendOne, Renderer::BlendOne);
4592 
4593 	if ((iX >= rZone.left) &&
4594 		(iY >= rZone.top) &&
4595 		(iX <= rZone.right) &&
4596 		(iY <= rZone.bottom))
4597 	{
4598 		if ((iX >= pLeftButton->rZone.left) &&
4599 			(iY >= pLeftButton->rZone.top) &&
4600 			(iX <= pLeftButton->rZone.right) &&
4601 			(iY <= pLeftButton->rZone.bottom))
4602 		{
4603 			pLeftButton->Render();
4604 
4605 		}
4606 		else if ((iX >= pRightButton->rZone.left) &&
4607 				(iY >= pRightButton->rZone.top) &&
4608 				(iX <= pRightButton->rZone.right) &&
4609 				(iY <= pRightButton->rZone.bottom))
4610 			{
4611 				pRightButton->Render();
4612 
4613 			}
4614 	}
4615 }
4616 
4617 
4618 //-----------------------------------------------------------------------------
4619 // CMenuSlider
4620 //-----------------------------------------------------------------------------
4621 
CMenuSlider(int _iID,int _iPosX,int _iPosY)4622 CMenuSlider::CMenuSlider(int _iID, int _iPosX, int _iPosY)
4623 	: CMenuElement(NOP)
4624 {
4625 	iID = _iID;
4626 
4627 	TextureContainer *pTexL = TextureContainer::Load("graph/interface/menus/menu_slider_button_left");
4628 	TextureContainer *pTexR = TextureContainer::Load("graph/interface/menus/menu_slider_button_right");
4629 	pLeftButton = new CMenuButton(-1, hFontMenu, NOP, _iPosX, _iPosY, string(), 1, pTexL, pTexR, -1);
4630 	pRightButton = new CMenuButton(-1, hFontMenu, NOP, _iPosX, _iPosY, string(), 1, pTexR, pTexL, -1);
4631 	pTex1 = TextureContainer::Load("graph/interface/menus/menu_slider_on");
4632 	pTex2 = TextureContainer::Load("graph/interface/menus/menu_slider_off");
4633 
4634 	iPos = 0;
4635 
4636 	rZone.left   = _iPosX;
4637 	rZone.top    = _iPosY;
4638 	rZone.right  = _iPosX + pLeftButton->GetWidth() + pRightButton->GetWidth() + 10*max(pTex1->m_dwWidth, pTex2->m_dwWidth);
4639 	rZone.bottom = _iPosY + max(pLeftButton->GetHeight(), pRightButton->GetHeight());
4640 
4641 	arx_assert(rZone.bottom >= 0);
4642 	rZone.bottom = max( static_cast<unsigned long>( rZone.bottom ), (unsigned long)max( pTex1->m_dwHeight, pTex2->m_dwHeight ) );
4643 
4644 
4645 	pRightButton->Move(pLeftButton->GetWidth() + 10*max(pTex1->m_dwWidth, pTex2->m_dwWidth), 0);
4646 
4647 	pRef = this;
4648 }
4649 
~CMenuSlider()4650 CMenuSlider::~CMenuSlider() {
4651 	delete pLeftButton;
4652 	delete pRightButton;
4653 }
4654 
Move(int _iX,int _iY)4655 void CMenuSlider::Move(int _iX, int _iY) {
4656 	CMenuZone::Move(_iX, _iY);
4657 	pLeftButton->Move(_iX, _iY);
4658 	pRightButton->Move(_iX, _iY);
4659 }
4660 
EmptyFunction()4661 void CMenuSlider::EmptyFunction()
4662 {
4663 	//Touche pour la selection
4664 	if(GInput->isKeyPressedNowPressed(Keyboard::Key_LeftArrow))
4665 	{
4666 		iPos--;
4667 
4668 		if (iPos <= 0) iPos = 0;
4669 	}
4670 	else
4671 	{
4672 		if(GInput->isKeyPressedNowPressed(Keyboard::Key_RightArrow))
4673 		{
4674 			iPos++;
4675 
4676 			if (iPos >= 10) iPos = 10;
4677 		}
4678 	}
4679 
4680 }
4681 
4682 //-----------------------------------------------------------------------------
4683 
OnMouseClick(int)4684 bool CMenuSlider::OnMouseClick(int)
4685 {
4686 	ARX_SOUND_PlayMenu(SND_MENU_CLICK);
4687 
4688 	int iX = GInput->getMousePosAbs().x;
4689 	int iY = GInput->getMousePosAbs().y;
4690 
4691 	if ((iX >= rZone.left) &&
4692 		(iY >= rZone.top) &&
4693 		(iX <= rZone.right) &&
4694 		(iY <= rZone.bottom))
4695 	{
4696 		if ((iX >= pLeftButton->rZone.left) &&
4697 			(iY >= pLeftButton->rZone.top) &&
4698 			(iX <= pLeftButton->rZone.right) &&
4699 			(iY <= pLeftButton->rZone.bottom))
4700 		{
4701 			iPos--;
4702 
4703 			if (iPos <= 0) iPos = 0;
4704 		}
4705 		else if ((iX >= pRightButton->rZone.left) &&
4706 				(iY >= pRightButton->rZone.top) &&
4707 				(iX <= pRightButton->rZone.right) &&
4708 				(iY <= pRightButton->rZone.bottom))
4709 			{
4710 				iPos++;
4711 
4712 				if (iPos >= 10) iPos = 10;
4713 			}
4714 	}
4715 
4716 	switch (iID)
4717 	{
4718 	// MENUOPTIONS_VIDEO
4719 	case BUTTON_MENUOPTIONSVIDEO_FOG:
4720 		ARXMenu_Options_Video_SetFogDistance(iPos);
4721 		break;
4722 	// MENUOPTIONS_AUDIO
4723 	case BUTTON_MENUOPTIONSAUDIO_MASTER:
4724 		ARXMenu_Options_Audio_SetMasterVolume(iPos);
4725 		break;
4726 	case BUTTON_MENUOPTIONSAUDIO_SFX:
4727 		ARXMenu_Options_Audio_SetSfxVolume(iPos);
4728 		break;
4729 	case BUTTON_MENUOPTIONSAUDIO_SPEECH:
4730 		ARXMenu_Options_Audio_SetSpeechVolume(iPos);
4731 		break;
4732 	case BUTTON_MENUOPTIONSAUDIO_AMBIANCE:
4733 		ARXMenu_Options_Audio_SetAmbianceVolume(iPos);
4734 		break;
4735 	// MENUOPTIONS_CONTROLS
4736 	case BUTTON_MENUOPTIONS_CONTROLS_MOUSESENSITIVITY:
4737 		ARXMenu_Options_Control_SetMouseSensitivity(iPos);
4738 		break;
4739 		case BUTTON_MENUOPTIONS_CONTROLS_QUICKSAVESLOTS: {
4740 			iPos = std::max(iPos, 1);
4741 			config.misc.quicksaveSlots = iPos;
4742 			break;
4743 		}
4744 	}
4745 
4746 	return false;
4747 }
4748 
4749 //-----------------------------------------------------------------------------
4750 
Update(int _iTime)4751 void CMenuSlider::Update(int _iTime) {
4752 
4753 	pLeftButton->Update(_iTime);
4754 	pRightButton->Update(_iTime);
4755 	pRightButton->SetPos(rZone.left, rZone.top);
4756 
4757 
4758 	float fWidth = pLeftButton->GetWidth() + RATIO_X(10*max(pTex1->m_dwWidth, pTex2->m_dwWidth)) ;
4759 	pRightButton->Move(checked_range_cast<int>(fWidth), 0);
4760 
4761 	rZone.right  = checked_range_cast<Rect::Num>( rZone.left + pLeftButton->GetWidth() + pRightButton->GetWidth() + RATIO_X(10*std::max(pTex1->m_dwWidth, pTex2->m_dwWidth)) );
4762 
4763 	rZone.bottom = rZone.top + std::max(pLeftButton->GetHeight(), pRightButton->GetHeight());
4764 }
4765 
Render()4766 void CMenuSlider::Render()
4767 {
4768 	if(bNoMenu) return;
4769 
4770 	pLeftButton->Render();
4771 	pRightButton->Render();
4772 
4773 
4774 	float iX = static_cast<float>( rZone.left + pLeftButton->GetWidth() );
4775 	float iY = static_cast<float>( rZone.top );
4776 
4777 	float iTexW = 0;
4778 
4779 	GRenderer->SetRenderState(Renderer::AlphaBlending, true);
4780 	GRenderer->SetBlendFunc(Renderer::BlendOne, Renderer::BlendOne);
4781 
4782 	TexturedVertex v[4];
4783 	v[0].color = v[1].color = v[2].color = v[3].color = Color::white.toBGR();
4784 	v[0].p.z=v[1].p.z=v[2].p.z=v[3].p.z=0.f;
4785 	v[0].rhw=v[1].rhw=v[2].rhw=v[3].rhw=0.999999f;
4786 
4787 	TextureContainer *pTex = pTex1;
4788 
4789 	for (int i=0; i<10; i++)
4790 	{
4791 		iTexW = 0;
4792 
4793 		if(i < iPos) {
4794 			if(pTex1) {
4795 				pTex = pTex1;
4796 				iTexW = RATIO_X(pTex1->m_dwWidth);
4797 			}
4798 		} else if(pTex2) {
4799 			pTex = pTex2;
4800 			iTexW = RATIO_X(pTex2->m_dwWidth);
4801 		}
4802 
4803 		if(pTex) {
4804 			EERIEDrawBitmap2(iX, iY, RATIO_X(pTex->m_dwWidth), RATIO_Y(pTex->m_dwHeight),
4805 			                 0, pTex, Color::white);
4806 		}
4807 
4808 		iX += iTexW;
4809 	}
4810 
4811 	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
4812 }
4813 
RenderMouseOver()4814 void CMenuSlider::RenderMouseOver()
4815 {
4816 	if(bNoMenu) return;
4817 
4818 	pMenuCursor->SetMouseOver();
4819 
4820 	int iX = GInput->getMousePosAbs().x;
4821 	int iY = GInput->getMousePosAbs().y;
4822 
4823 	GRenderer->SetRenderState(Renderer::AlphaBlending, true);
4824 	GRenderer->SetBlendFunc(Renderer::BlendOne, Renderer::BlendOne);
4825 
4826 	if ((iX >= rZone.left) &&
4827 		(iY >= rZone.top) &&
4828 		(iX <= rZone.right) &&
4829 		(iY <= rZone.bottom))
4830 	{
4831 		if ((iX >= pLeftButton->rZone.left) &&
4832 			(iY >= pLeftButton->rZone.top) &&
4833 			(iX <= pLeftButton->rZone.right) &&
4834 			(iY <= pLeftButton->rZone.bottom))
4835 		{
4836 			pLeftButton->Render();
4837 
4838 		}
4839 		else if ((iX >= pRightButton->rZone.left) &&
4840 				(iY >= pRightButton->rZone.top) &&
4841 				(iX <= pRightButton->rZone.right) &&
4842 				(iY <= pRightButton->rZone.bottom))
4843 		{
4844 			pRightButton->Render();
4845 		}
4846 	}
4847 
4848 	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
4849 }
4850 
4851 //-----------------------------------------------------------------------------
4852 
MenuCursor()4853 MenuCursor::MenuCursor()
4854 {
4855 	pTex[0]=TextureContainer::Find("graph/interface/cursors/cursor00");
4856 	pTex[1]=TextureContainer::Find("graph/interface/cursors/cursor01");
4857 	pTex[2]=TextureContainer::Find("graph/interface/cursors/cursor02");
4858 	pTex[3]=TextureContainer::Find("graph/interface/cursors/cursor03");
4859 	pTex[4]=TextureContainer::Find("graph/interface/cursors/cursor04");
4860 	pTex[5]=TextureContainer::Find("graph/interface/cursors/cursor05");
4861 	pTex[6]=TextureContainer::Find("graph/interface/cursors/cursor06");
4862 	pTex[7]=TextureContainer::Find("graph/interface/cursors/cursor07");
4863 
4864 	SetCursorOff();
4865 
4866 	iNbOldCoord=0;
4867 	iMaxOldCoord=40;
4868 
4869 	exited = true;
4870 
4871 	bMouseOver=false;
4872 
4873 	if(pTex[0])
4874 	{
4875 		fTailleX=(float)pTex[0]->m_dwWidth;
4876 		fTailleY=(float)pTex[0]->m_dwHeight;
4877 	}
4878 	else
4879 	{
4880 		fTailleX=fTailleY=0.f;
4881 	}
4882 
4883 	iNumCursor=0;
4884 	lFrameDiff=0;
4885 
4886 	bDrawCursor=true;
4887 }
4888 
4889 //-----------------------------------------------------------------------------
4890 
~MenuCursor()4891 MenuCursor::~MenuCursor()
4892 {
4893 }
4894 
4895 //-----------------------------------------------------------------------------
4896 
SetCursorOff()4897 void MenuCursor::SetCursorOff()
4898 {
4899 	eNumTex=CURSOR_OFF;
4900 }
4901 
4902 //-----------------------------------------------------------------------------
4903 
SetCursorOn()4904 void MenuCursor::SetCursorOn()
4905 {
4906 	eNumTex=CURSOR_ON;
4907 }
4908 
4909 //-----------------------------------------------------------------------------
4910 
SetMouseOver()4911 void MenuCursor::SetMouseOver()
4912 {
4913 	bMouseOver=true;
4914 	SetCursorOn();
4915 }
4916 
4917 //-----------------------------------------------------------------------------
4918 
DrawOneCursor(const Vec2s & mousePos)4919 void MenuCursor::DrawOneCursor(const Vec2s& mousePos) {
4920 
4921 	if(!GInput->isMouseInWindow()) {
4922 		return;
4923 	}
4924 
4925 	GRenderer->GetTextureStage(0)->SetMinFilter(TextureStage::FilterNearest);
4926 	GRenderer->GetTextureStage(0)->SetMagFilter(TextureStage::FilterNearest);
4927 	GRenderer->GetTextureStage(0)->SetWrapMode(TextureStage::WrapClamp);
4928 	EERIEDrawBitmap2(static_cast<float>(mousePos.x), static_cast<float>(mousePos.y),
4929 	                 INTERFACE_RATIO_DWORD(scursor[iNumCursor]->m_dwWidth),
4930 	                 INTERFACE_RATIO_DWORD(scursor[iNumCursor]->m_dwHeight),
4931 	                 0.00000001f, scursor[iNumCursor], Color::white);
4932 	GRenderer->GetTextureStage(0)->SetMinFilter(TextureStage::FilterLinear);
4933 	GRenderer->GetTextureStage(0)->SetMagFilter(TextureStage::FilterLinear);
4934 	GRenderer->GetTextureStage(0)->SetWrapMode(TextureStage::WrapRepeat);
4935 }
4936 
4937 //-----------------------------------------------------------------------------
4938 
Update()4939 void MenuCursor::Update() {
4940 
4941 	bool inWindow = GInput->isMouseInWindow();
4942 	if(inWindow && exited) {
4943 		// Mouse is re-entering the window - reset the cursor trail
4944 		iNbOldCoord = 0;
4945 	}
4946 	exited = !inWindow;
4947 
4948 	Vec2s iDiff;
4949 	if(pTex[eNumTex]) {
4950 		iDiff = Vec2s(pTex[eNumTex]->m_dwWidth / 2, pTex[eNumTex]->m_dwHeight / 2);
4951 	} else {
4952 		iDiff = Vec2s::ZERO;
4953 	}
4954 
4955 	iOldCoord[iNbOldCoord] = GInput->getMousePosAbs() + iDiff;
4956 	iNbOldCoord++;
4957 
4958 	if(iNbOldCoord >= iMaxOldCoord) {
4959 		iNbOldCoord = iMaxOldCoord - 1;
4960 		memmove(iOldCoord, iOldCoord + 1, sizeof(Vec2s) * iNbOldCoord);
4961 	}
4962 
4963 }
4964 
4965 //-----------------------------------------------------------------------------
4966 
ComputePer(const Vec2s & _psPoint1,const Vec2s & _psPoint2,TexturedVertex * _psd3dv1,TexturedVertex * _psd3dv2,float _fSize)4967 static bool ComputePer(const Vec2s & _psPoint1, const Vec2s & _psPoint2, TexturedVertex * _psd3dv1, TexturedVertex * _psd3dv2, float _fSize) {
4968 
4969 	Vec2f sTemp((float)(_psPoint2.x - _psPoint1.x), (float)(_psPoint2.y - _psPoint1.y));
4970 	float fTemp = sTemp.x;
4971 	sTemp.x = -sTemp.y;
4972 	sTemp.y = fTemp;
4973 	float fMag = sTemp.length();
4974 	if(fMag < std::numeric_limits<float>::epsilon()) {
4975 		return false;
4976 	}
4977 
4978 	fMag = _fSize / fMag;
4979 
4980 	_psd3dv1->p.x=(sTemp.x*fMag);
4981 	_psd3dv1->p.y=(sTemp.y*fMag);
4982 	_psd3dv2->p.x=((float)_psPoint1.x)-_psd3dv1->p.x;
4983 	_psd3dv2->p.y=((float)_psPoint1.y)-_psd3dv1->p.y;
4984 	_psd3dv1->p.x+=((float)_psPoint1.x);
4985 	_psd3dv1->p.y+=((float)_psPoint1.y);
4986 
4987 	return true;
4988 }
4989 
4990 //-----------------------------------------------------------------------------
4991 
DrawLine2D(const Vec2s * points,int _iNbPt,float _fSize,float _fRed,float _fGreen,float _fBlue)4992 static void DrawLine2D(const Vec2s * points, int _iNbPt, float _fSize, float _fRed, float _fGreen, float _fBlue) {
4993 
4994 	if(_iNbPt < 2) {
4995 		return;
4996 	}
4997 
4998 	float fSize = _fSize / _iNbPt;
4999 	float fTaille = fSize;
5000 
5001 	float fDColorRed = _fRed / _iNbPt;
5002 	float fColorRed = fDColorRed;
5003 	float fDColorGreen = _fGreen / _iNbPt;
5004 	float fColorGreen = fDColorGreen;
5005 	float fDColorBlue = _fBlue / _iNbPt;
5006 	float fColorBlue = fDColorBlue;
5007 
5008 	GRenderer->SetBlendFunc(Renderer::BlendDstColor, Renderer::BlendInvDstColor);
5009 	GRenderer->ResetTexture(0);
5010 	GRenderer->SetRenderState(Renderer::AlphaBlending, true);
5011 
5012 	TexturedVertex v[4];
5013 	v[0].p.z = v[1].p.z = v[2].p.z = v[3].p.z = 0.f;
5014 	v[0].rhw = v[1].rhw = v[2].rhw = v[3].rhw = 0.999999f;
5015 
5016 	v[0].color = v[2].color = Color3f(fColorRed, fColorGreen, fColorBlue).toBGR();
5017 
5018 	if(!ComputePer(points[0], points[1], &v[0], &v[2], fTaille)) {
5019 		v[0].p.x = v[2].p.x = points[0].x;
5020 		v[0].p.y = v[2].p.y = points[1].y;
5021 	}
5022 
5023 	for(int i = 1; i < _iNbPt - 1; i++) {
5024 
5025 		fTaille += fSize;
5026 		fColorRed += fDColorRed;
5027 		fColorGreen += fDColorGreen;
5028 		fColorBlue += fDColorBlue;
5029 
5030 		if(ComputePer(points[i], points[i + 1], &v[1], &v[3], fTaille)) {
5031 
5032 			v[1].color = v[3].color = Color3f(fColorRed, fColorGreen, fColorBlue).toBGR();
5033 			EERIEDRAWPRIM(Renderer::TriangleStrip, v, 4);
5034 
5035 			v[0].p.x = v[1].p.x;
5036 			v[0].p.y = v[1].p.y;
5037 			v[0].color = v[1].color;
5038 			v[2].p.x = v[3].p.x;
5039 			v[2].p.y = v[3].p.y;
5040 			v[2].color = v[3].color;
5041 		}
5042 
5043 	}
5044 
5045 	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
5046 }
5047 
5048 //-----------------------------------------------------------------------------
5049 
DrawCursor()5050 void MenuCursor::DrawCursor()
5051 {
5052 	if(!bDrawCursor)
5053 		return;
5054 
5055 	GRenderer->SetRenderState(Renderer::AlphaBlending, true);
5056 	DrawLine2D(iOldCoord, iNbOldCoord, 10.f, .725f, .619f, 0.56f);
5057 
5058 	if(pTex[iNumCursor])
5059 		GRenderer->SetTexture(0, pTex[iNumCursor]);
5060 	else
5061 		GRenderer->ResetTexture(0);
5062 
5063 	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
5064 
5065 	GRenderer->SetRenderState(Renderer::DepthTest, false);
5066 	DrawOneCursor(GInput->getMousePosAbs());
5067 	GRenderer->SetRenderState(Renderer::DepthTest, true);
5068 
5069 	lFrameDiff += checked_range_cast<long>(ARXDiffTimeMenu);
5070 
5071 	if(lFrameDiff>70)
5072 	{
5073 		if(bMouseOver)
5074 		{
5075 			if(iNumCursor<4)
5076 			{
5077 				iNumCursor++;
5078 			}
5079 			else
5080 			{
5081 				if(iNumCursor>4)
5082 				{
5083 					iNumCursor--;
5084 				}
5085 			}
5086 
5087 			SetCursorOff();
5088 			bMouseOver=false;
5089 		}
5090 		else
5091 		{
5092 			if (iNumCursor > 0)
5093 			{
5094 				iNumCursor++;
5095 
5096 				if(iNumCursor>7) iNumCursor=0;
5097 			}
5098 		}
5099 
5100 		lFrameDiff=0;
5101 	}
5102 
5103 	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
5104 }
5105 
Menu2_Close()5106 void Menu2_Close() {
5107 
5108 	ARXmenu.currentmode = AMCM_OFF;
5109 
5110 	delete pWindowMenu, pWindowMenu = NULL;
5111 	delete pMenu, pMenu = NULL;
5112 	delete pMenuCursor, pMenuCursor = NULL;
5113 }
5114