Use configured resolution for login/outgame/ingame
[ryzomcore.git] / ryzom / tools / client / client_config / preset_dlg.cpp
blob528420a67f50c4490c1ac315c2dd3b7c3c3fb87d
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // preset_dlg.cpp : implementation file
20 todo hulud remove
22 #include "stdafx.h"
23 #include "client_config.h"
24 #include "preset_dlg.h"
25 #include "database.h"
26 #include "display_dlg.h"
27 #include "cfg_file.h"
29 #undef max
31 using namespace NLMISC;
33 /////////////////////////////////////////////////////////////////////////////
34 // CPresetDlg dialog
37 CPresetDlg::CPresetDlg(CWnd* pParent /*=NULL*/)
38 : CDialog(CPresetDlg::IDD, pParent)
40 //{{AFX_DATA_INIT(CPresetDlg)
41 CPUFrequency = _T("");
42 SystemMemory = _T("");
43 VideoCard = -1;
44 VideoMemory = _T("");
45 HardwareSoundBuffer = _T("");
46 //}}AFX_DATA_INIT
50 void CPresetDlg::DoDataExchange(CDataExchange* pDX)
52 CDialog::DoDataExchange(pDX);
53 //{{AFX_DATA_MAP(CPresetDlg)
54 DDX_Control(pDX, IDOK, OkCtrl);
55 DDX_Control(pDX, IDCANCEL, CancelCtrl);
56 DDX_Control(pDX, IDC_VIDEO_CARD, VideoCardCtrl);
57 DDX_Text(pDX, IDC_CPU_FREQUENCY, CPUFrequency);
58 DDX_Text(pDX, IDC_SYSTEM_MEMORY, SystemMemory);
59 DDX_CBIndex(pDX, IDC_VIDEO_CARD, VideoCard);
60 DDX_Text(pDX, IDC_VIDEO_MEMORY, VideoMemory);
61 DDX_Text(pDX, IDC_HARDWARE_SOUND_BUFFER, HardwareSoundBuffer);
62 //}}AFX_DATA_MAP
66 BEGIN_MESSAGE_MAP(CPresetDlg, CDialog)
67 //{{AFX_MSG_MAP(CPresetDlg)
68 ON_BN_CLICKED(IDC_RESET, OnReset)
69 //}}AFX_MSG_MAP
70 END_MESSAGE_MAP()
72 /////////////////////////////////////////////////////////////////////////////
73 // CPresetDlg message handlers
75 void CPresetDlg::OnReset()
77 // TODO: Add your control notification handler code here
81 BOOL CPresetDlg::OnInitDialog()
83 CDialog::OnInitDialog();
85 // Set the video card list
86 uint i;
87 for (i=0; i<CVideoCard::CardCount; i++)
88 VideoCardCtrl.AddString (GetString (VideoCards[i].DisplayString));
90 // Select the good video card
91 for (VideoCard=0; VideoCard<CVideoCard::CardCount; VideoCard++)
93 bool found = false;
94 // For each keyword
95 uint j;
96 for (j=0; j<CVideoCard::TokenCount; j++)
98 // Check it is not an empty keyword
99 if (strcmp (VideoCards[VideoCard].MatchingTokens[j], "") != 0)
101 // Look for the keyword in the tokens
102 char str[512];
103 strcpy (str, GLRenderer.c_str ());
104 const char *token = strtok( str, " ");
105 while( token != NULL )
107 if (stricmp (token, VideoCards[VideoCard].MatchingTokens[j]) == 0)
109 found = true;
110 break;
113 // Get next token
114 token = strtok( NULL, " ");
117 // Not found ?
118 if (!token)
119 break;
123 // Found ?
124 if (found && (j == CVideoCard::TokenCount))
125 break;
128 // Found ?
129 if (VideoCard == CVideoCard::CardCount)
130 VideoCard = 0;
132 UpdateData (FALSE);
134 return TRUE; // return TRUE unless you set the focus to a control
135 // EXCEPTION: OCX Property Pages should return FALSE
138 void CPresetDlg::OnOK()
140 UpdateData ();
141 // Choose a video card
142 if (VideoCard == 0)
144 MessageBoxW (GetString (IDS_CHOOSE_A_CARD), CI18N::get ("uiConfigTitle"), MB_OK|MB_ICONEXCLAMATION);
146 else
148 // Reset the CFG
149 ResetConfigFile ();
151 // Reset the widgets
152 GetFromConfigFile ();
154 // Merge the config files
155 MergeConfigFile (ConfigFilePreset[((::SystemMemory / (1024*1024)) < 500)?RAM256:RAM512]);
156 MergeConfigFile (ConfigFilePreset[(::CPUFrequency < 1500)?CPU1:(::CPUFrequency < 2000)?CPU2:(::CPUFrequency < 2500)?CPU3:CPU4]);
157 MergeConfigFile (ConfigFilePreset[VideoCards[VideoCard].Preset]);
158 int vram = ::VideoMemory / (1024*1024);
159 MergeConfigFile (ConfigFilePreset[(vram < 50)?VRAM32:(vram < 100)?VRAM64:VRAM128]);
160 CConfigFile::CVar *var = ConfigFilePreset[SoundBuffer].getVarPtr ("MaxTrack");
161 if (var && var->Type)
163 var->setAsInt (::HardwareSoundBuffer);
164 MergeConfigFile (ConfigFilePreset[SoundBuffer]);
167 CDialog::OnOK();
171 void CPresetDlg::OnCancel()
173 CDialog::OnCancel();