void GameSettings::setOption(const ConfigOptionMap& configuration, const Ogre::String& option, Combobox* combobox) { ConfigOptionMap::const_iterator cfi = configuration.find(option); if (cfi != configuration.end()) { ConfigOption curOption = cfi->second; int delta = curOption.possibleValues.size() - combobox->getItemCount(); if (delta > 0) { for (int i = 0; i < delta; ++i) { combobox->addItem(new ListboxTextItem("")); } } else if (delta < 0) { for (int i = 0; i < -delta; ++i) { ListboxItem* item = combobox->getListboxItemFromIndex(combobox->getItemCount() - 1); combobox->removeItem(item); delete item; } } for (unsigned int i = 0; i < combobox->getItemCount(); ++i) { ListboxItem* item = combobox->getListboxItemFromIndex(i); item->setText(curOption.possibleValues[i]); } } }
void GameSettings::setOption(const ConfigOptionMap& configuration, const Ogre::String& option, Checkbox* checkbox) { ConfigOptionMap::const_iterator cfi = configuration.find(option); if (cfi != configuration.end()) { checkbox->setSelected(cfi->second.currentValue == "Yes"); } }
void ConfigDialog::setupRendererParams () { // Remove all existing child widgets gtk_container_forall (GTK_CONTAINER (mParamTable), remove_all_callback, mParamTable); ConfigOptionMap options = mSelectedRenderSystem->getConfigOptions (); // Resize the table to hold as many options as we have gtk_table_resize (GTK_TABLE (mParamTable), options.size (), 2); uint row = 0; for (ConfigOptionMap::iterator i = options.begin (); i != options.end (); i++, row++) { if (i->second.possibleValues.empty()) { continue; } GtkWidget *ro_label = gtk_label_new (i->second.name.c_str ()); gtk_widget_show (ro_label); gtk_table_attach (GTK_TABLE (mParamTable), ro_label, 0, 1, row, row + 1, GtkAttachOptions (GTK_EXPAND | GTK_FILL), GtkAttachOptions (0), 5, 0); gtk_label_set_justify (GTK_LABEL (ro_label), GTK_JUSTIFY_RIGHT); gtk_misc_set_alignment (GTK_MISC (ro_label), 1, 0.5); GtkWidget *ro_cb = gtk_combo_box_new_text (); gtk_widget_show (ro_cb); gtk_table_attach (GTK_TABLE (mParamTable), ro_cb, 1, 2, row, row + 1, GtkAttachOptions (GTK_EXPAND | GTK_FILL), GtkAttachOptions (0), 5, 0); // Set up a link from the combobox to the label g_object_set_data (G_OBJECT (ro_cb), "renderer-option", ro_label); StringVector::iterator opt_it; uint idx = 0; for (opt_it = i->second.possibleValues.begin (); opt_it != i->second.possibleValues.end (); opt_it++, idx++) { gtk_combo_box_append_text (GTK_COMBO_BOX (ro_cb), (*opt_it).c_str ()); if (strcmp (i->second.currentValue.c_str (), (*opt_it).c_str ()) == 0) gtk_combo_box_set_active (GTK_COMBO_BOX (ro_cb), idx); } g_signal_connect (G_OBJECT (ro_cb), "changed", G_CALLBACK (optionChanged), this); } gtk_widget_grab_focus (GTK_WIDGET (mOKButton)); }
void GameSettings::setOption(const ConfigOptionMap& configuration, const Ogre::String& option, std::vector<RadioButton*> radioGroup) { ConfigOptionMap::const_iterator cfi = configuration.find(option); if (cfi != configuration.end()) { ConfigOption curOption = cfi->second; for (std::vector<RadioButton*>::const_iterator it = radioGroup.begin(); it != radioGroup.end(); ++it) { Ogre::String* value = static_cast<Ogre::String*>((*it)->getUserData()); if (value && (*value == curOption.currentValue)) { (*it)->setSelected(true); break; } } } }
void GLXConfigurator::SetRenderer(RenderSystem *r) { mRenderer = r; // Destroy each widget of GUI of previously selected renderer for(std::list<Widget>::iterator i=mRenderOptionWidgets.begin(); i!=mRenderOptionWidgets.end(); i++) XtDestroyWidget(*i); mRenderOptionWidgets.clear(); mConfigCallbackData.back(); // Create option GUI int cury = ystart + 1*rowh + 10; ConfigOptionMap options = mRenderer->getConfigOptions(); // Process each option and create an optionmenu widget for it for (ConfigOptionMap::iterator it = options.begin(); it != options.end(); it++) { // if the config option does not have any possible value, then skip it. // if we create a popup with zero entries, it will crash when you click // on it. if (it->second.possibleValues.empty()) continue; Widget lb1 = XtVaCreateManagedWidget("topLabel", labelWidgetClass, box, XtNlabel, it->second.name.c_str(), XtNborderWidth, 0, XtNwidth, col1w, // Fixed width XtNheight, 18, XtNleft, XawChainLeft, XtNtop, XawChainTop, XtNright, XawChainLeft, XtNbottom, XawChainTop, XtNhorizDistance, col1x, XtNvertDistance, cury, XtNjustify, XtJustifyLeft, NULL); mRenderOptionWidgets.push_back(lb1); Widget mb1 = XtVaCreateManagedWidget("Menu", menuButtonWidgetClass, box, XtNlabel, it->second.currentValue.c_str(), XtNresize, false, XtNresizable, false, XtNwidth, col2w, // Fixed width XtNheight, 18, XtNleft, XawChainLeft, XtNtop, XawChainTop, XtNright, XawChainLeft, XtNbottom, XawChainTop, XtNhorizDistance, col2x, XtNvertDistance, cury, NULL); mRenderOptionWidgets.push_back(mb1); Widget menu = XtVaCreatePopupShell("menu", simpleMenuWidgetClass, mb1, 0, NULL); // Process each choice StringVector::iterator opt_it; for (opt_it = it->second.possibleValues.begin(); opt_it != it->second.possibleValues.end(); opt_it++) { // Create callback data mConfigCallbackData.push_back(ConfigCallbackData(this, it->second.name, *opt_it, mb1)); Widget entry = XtVaCreateManagedWidget("menuentry", smeBSBObjectClass, menu, XtNlabel, (*opt_it).c_str(), 0, NULL); XtAddCallback(entry, XtNcallback, (XtCallbackProc)&GLXConfigurator::configOptionHandler, &mConfigCallbackData.back()); } cury += rowh; } }
RenderSystem* ApplicationSettings::ConfigureRenderSystem(RenderSystem* renderSystem) { const size_t bitDepth = 32; //Set the rendering system if (renderSystem == 0) renderSystem = GetConfiguredRenderSystem(); if (renderSystem == 0) renderSystem = Root::getSingleton().getAvailableRenderers()->front(); Root::getSingleton().setRenderSystem(renderSystem); //Configure the render system ConfigOptionMap configOptions = renderSystem->getConfigOptions(); for (ConfigOptionMap::iterator configItem = configOptions.begin(); configItem != configOptions.end(); ++configItem) { String name = configItem->first; if (name == "Video Mode") { StringUtil::StrStreamType videoMode; videoMode << this->screenWidth << " x " << this->screenHeight << " @ " << bitDepth << "-bit colour" ; String value = videoMode.str(); renderSystem->setConfigOption(name, value); } else if (name == "Colour Depth") { String value = StringConverter::toString(bitDepth); renderSystem->setConfigOption(name, value); } else if (name == "Full Screen") { renderSystem->setConfigOption(name, this->fullScreen ? "Yes" : "No"); } else if (name == "VSync") { renderSystem->setConfigOption(name, this->vsync ? "Yes" : "No"); } else if (name == "Display Frequency") { if (this->fullScreen) { String value = StringConverter::toString(this->fullScreenRefreshRate); renderSystem->setConfigOption(name, value); } } else if (name == "Allow NVPerfHUD") { renderSystem->setConfigOption(name, this->enableNvidiaPerformanceHUD ? "Yes" : "No"); } } String message = renderSystem->validateConfigOptions(); if (!message.empty()) { StringUtil::StrStreamType errorMessage; errorMessage << "Unable to validate configuration options: " << message; OGRE_EXCEPT ( Exception::ERR_INVALIDPARAMS, errorMessage.str(), "ApplicationSettings::ConfigureRenderSystem" ); } return renderSystem; }
BOOL ConfigDialog::DlgProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam) #endif { HWND hwndDlgItem; static RenderSystemList* lstRend; RenderSystemList::iterator pRend; static ConfigOptionMap opts; String err; int i, sel, savedSel; switch (iMsg) { case WM_INITDIALOG: // Load saved settings dlg->mSelectedRenderSystem = Root::getSingleton().getRenderSystem(); // Get all render systems lstRend = Root::getSingleton().getAvailableRenderers(); pRend = lstRend->begin(); i = 0; while (pRend != lstRend->end()) { hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_RENDERSYSTEM); SendMessage(hwndDlgItem, CB_ADDSTRING, 0, (LPARAM)(char*)(*pRend)->getName().c_str()); if (*pRend == dlg->mSelectedRenderSystem) { // Select SendMessage(hwndDlgItem, CB_SETCURSEL, (WPARAM)i, 0); // Refresh Options // Get options from render system opts = (*pRend)->getConfigOptions(); // Reset list box hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS); //SendMessage(hwndDlgItem, LB_RESETCONTENT, 0, 0); // Iterate through options ConfigOptionMap::iterator pOpt = opts.begin(); String strLine; while( pOpt!= opts.end() ) { strLine = pOpt->second.name + ": " + pOpt->second.currentValue; SendMessage(hwndDlgItem, LB_ADDSTRING, 0, (LPARAM)strLine.c_str()); ++pOpt; } } ++pRend; ++i; } // Center myself int x, y, screenWidth, screenHeight; RECT rcDlg; GetWindowRect(hDlg, &rcDlg); screenWidth = GetSystemMetrics(SM_CXFULLSCREEN); screenHeight = GetSystemMetrics(SM_CYFULLSCREEN); x = (screenWidth / 2) - ((rcDlg.right - rcDlg.left) / 2); y = (screenHeight / 2) - ((rcDlg.bottom - rcDlg.top) / 2); MoveWindow(hDlg, x, y, (rcDlg.right - rcDlg.left), (rcDlg.bottom - rcDlg.top), TRUE); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_CBO_RENDERSYSTEM: hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_RENDERSYSTEM); sel = SendMessage( hwndDlgItem, CB_GETCOUNT, 0, 0 ); if (HIWORD(wParam) == CBN_SELCHANGE ) { // RenderSystem selected // Get selected index hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_RENDERSYSTEM); sel = SendMessage(hwndDlgItem, CB_GETCURSEL,0,0); if (sel != -1) { // Get RenderSystem selected pRend = lstRend->begin(); dlg->mSelectedRenderSystem = pRend[sel]; // refresh options // Get options from render system opts = pRend[sel]->getConfigOptions(); // Reset list box hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS); SendMessage(hwndDlgItem, LB_RESETCONTENT, 0, 0); // Iterate through options ConfigOptionMap::iterator pOpt = opts.begin(); String strLine; while (pOpt!=opts.end()) { strLine = pOpt->second.name + ": " + pOpt->second.currentValue; SendMessage(hwndDlgItem, LB_ADDSTRING, 0, (LPARAM)strLine.c_str()); ++pOpt; } } } return TRUE; case IDC_LST_OPTIONS: if (HIWORD(wParam) == LBN_SELCHANGE) { // Selection in list box of options changed // Update combo and label in edit section hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS); sel = SendMessage(hwndDlgItem, LB_GETCURSEL, 0, 0); if (sel != -1) { ConfigOptionMap::iterator pOpt = opts.begin(); for (i = 0; i < sel; i++) ++pOpt; // Set label text hwndDlgItem = GetDlgItem(hDlg, IDC_LBL_OPTION); SetWindowText(hwndDlgItem, pOpt->second.name.c_str()); // Set combo options hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_OPTION); SendMessage(hwndDlgItem, CB_RESETCONTENT, 0, 0); StringVector::iterator pPoss = pOpt->second.possibleValues.begin(); i = 0; while (pPoss!=pOpt->second.possibleValues.end()) { SendMessage(hwndDlgItem, CB_ADDSTRING, 0, (LPARAM)pPoss[0].c_str()); if (pPoss[0] == pOpt->second.currentValue) // Select current value SendMessage(hwndDlgItem, CB_SETCURSEL, (WPARAM)i, 0); ++pPoss; ++i; } // Enable/disable combo depending on (not)immutable EnableWindow(hwndDlgItem, !(pOpt->second.immutable)); } } return TRUE; case IDC_CBO_OPTION: if (HIWORD(wParam) == CBN_SELCHANGE) { // Updated an option // Get option hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS); sel = SendMessage(hwndDlgItem, LB_GETCURSEL, 0, 0); savedSel = sel; ConfigOptionMap::iterator pOpt = opts.begin(); for (i = 0; i < sel; i++) ++pOpt; // Get selected value hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_OPTION); sel = SendMessage(hwndDlgItem, CB_GETCURSEL, 0, 0); if (sel != -1) { StringVector::iterator pPoss = pOpt->second.possibleValues.begin(); // Set option dlg->mSelectedRenderSystem->setConfigOption( pOpt->second.name, pPoss[sel]); // Re-retrieve options opts = dlg->mSelectedRenderSystem->getConfigOptions(); // Reset options list box hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS); SendMessage(hwndDlgItem, LB_RESETCONTENT, 0, 0); // Iterate through options pOpt = opts.begin(); String strLine; while (pOpt!=opts.end()) { strLine = pOpt->second.name + ": " + pOpt->second.currentValue; SendMessage(hwndDlgItem, LB_ADDSTRING, 0, (LPARAM)strLine.c_str()); ++pOpt; } // Select previously selected item SendMessage(hwndDlgItem, LB_SETCURSEL, savedSel, 0); } } return TRUE; case IDOK: // Set render system if (!dlg->mSelectedRenderSystem) { MessageBox(NULL, "Please choose a rendering system.", "OGRE", MB_OK | MB_ICONEXCLAMATION); return TRUE; } err = dlg->mSelectedRenderSystem->validateConfigOptions(); if (err.length() > 0) { // refresh options incase updated by validation // Get options from render system opts = dlg->mSelectedRenderSystem->getConfigOptions(); // Reset list box hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS); SendMessage(hwndDlgItem, LB_RESETCONTENT, 0, 0); // Iterate through options ConfigOptionMap::iterator pOpt = opts.begin(); String strLine; while (pOpt!=opts.end()) { strLine = pOpt->second.name + ": " + pOpt->second.currentValue; SendMessage(hwndDlgItem, LB_ADDSTRING, 0, (LPARAM)strLine.c_str()); ++pOpt; } MessageBox(NULL, err.c_str(), "OGRE", MB_OK | MB_ICONEXCLAMATION); return TRUE; } Root::getSingleton().setRenderSystem(dlg->mSelectedRenderSystem); EndDialog(hDlg, TRUE); return TRUE; case IDCANCEL: EndDialog(hDlg, FALSE); return TRUE; } } return FALSE; }