void CColosseumCtrl::incrementProgressBar(bool hide ) { CDXUTSlider* slider = m_dialog.GetSlider(IDC_SLIDER); int x = slider->GetValue(); if(x >= ((SLIDER_MAX_VALUE - 1) * m_endpointModelVector.size())) slider->SetVisible(false); slider->SetValue(++x); }
float slider_value(int idc, int mi, int ma) { CDXUTSlider* slider = dynamic_cast<CDXUTSlider*>(find_control(idc)); float v = static_cast<float>(slider->GetValue()); if (mi == 0 && ma == 0) slider->GetRange(mi, ma); v /= static_cast<float>(ma - mi); return v; }
void CALLBACK HUD::onGuiEvent(UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext) { WCHAR sz[200]; Game* game = (Game*)pUserContext; Terrain* terrain = game->terrain; Camera* camera = game->camera; switch (nControlID) { case CameraMovementSlider: { CDXUTSlider* slider = (CDXUTSlider*)pControl; int movement = slider->GetValue(); camera->setMovementSpeed((float)movement); StringCchPrintf(sz, 200, L"Camera Movement: %d", movement); dialog.GetStatic(CameraMovementStatic)->SetText(sz); } break; case BumpinessSlider: { CDXUTSlider* slider = (CDXUTSlider*)pControl; int bumpiness = slider->GetValue(); terrain->setBumpiness((float)bumpiness); StringCchPrintf(sz, 200, L"Bumpiness: %d", bumpiness); dialog.GetStatic(BumpinessStatic)->SetText(sz); } break; case MinPixelPerTriangleSlider: { CDXUTSlider* slider = (CDXUTSlider*)pControl; float minPixelPerTriangle = slider->GetValue() / 100.0f; terrain->setMinPixelPerTriangle(minPixelPerTriangle); StringCchPrintf(sz, 200, L"Triangle Size: %.2f", minPixelPerTriangle); dialog.GetStatic(MinPixelPerTriangleStatic)->SetText(sz); } break; case RoughnessModificatorSlider: { CDXUTSlider* slider = (CDXUTSlider*)pControl; float roughnessModificator = slider->GetValue() / 100.0f; terrain->setRoughnessModificator(roughnessModificator); StringCchPrintf(sz, 200, L"Roughness Modificator: %.2f", roughnessModificator); dialog.GetStatic(RoughnessModificatorStatic)->SetText(sz); } break; case TextureRepeatSlider: { CDXUTSlider* slider = (CDXUTSlider*)pControl; int textureRepeat = slider->GetValue(); terrain->setColormapRepeat((float)textureRepeat); StringCchPrintf(sz, 200, L"Texture Repeat: %d", textureRepeat); dialog.GetStatic(TextureRepeatStatic)->SetText(sz); } break; case WireframeCheckbox: { game->toggleWireframe(); } break; case UpdateLODCheckbox: { camera->toggleLock(); } break; case CPUFrustumCullingCheckbox: { terrain->setCPUFrustumCullingEnabled(!terrain->getCPUFrustumCullingEnabled()); } break; case GPUFrustumCullingCheckbox: { terrain->setGPUFrustumCullingEnabled(!terrain->getGPUFrustumCullingEnabled()); } break; case SnapToTerrainCheckbox: { game->toggleFreeCamera(); } break; case LightingCheckbox: { terrain->setLightingEnabled(!terrain->getLightingEnabled()); } break; case HeightTextureCheckbox: { terrain->setHeightTextureEnabled(!terrain->getHeightTextureEnabled()); } break; case SlopeTextureCheckbox: { terrain->setSlopeTextureEnabled(!terrain->getSlopeTextureEnabled()); } break; case RoughnessCheckbox: { terrain->setRoughnessEnabled(!terrain->getRoughnessEnabled()); } break; case AntiShimmeringCheckbox: { terrain->setAntiShimmeringEnabled(!terrain->getAntiShimmeringEnabled()); } break; case ShowNodesCheckbox: { terrain->setShowNodesEnabled(!terrain->getShowNodesEnabled()); } break; case UniformPatchSizeCheckbox: { terrain->setUniformPatchSizeEnabled(!terrain->getUniformPatchSizeEnabled()); } break; case BruteForceCheckbox: { terrain->setBruteForceEnabled(!terrain->getBruteForceEnabled()); } break; case ColormapCheckbox: { terrain->setColormapEnabled(!terrain->getColormapEnabled()); } break; } }
//================================================================================== void CALLBACK gOnUIPageEvent( UINT nEvent, NxI32 nControlID, CDXUTControl* pControl ) { CDXUTDialog *dialog = pControl->m_pDialog; void *userdata = dialog->GetUserData(); if ( userdata ) { TuiElement *page = (TuiElement *) userdata; TextUserInterface *tui = gTui; if ( page ) { TuiElement *ret = page->GetElement( nControlID-1 ); switch ( ret->GetType() ) { case TT_MULTI_SELECT: { switch( nEvent ) { case EVENT_LISTBOX_ITEM_DBLCLK: { //DXUTListBoxItem *pItem = ((CDXUTListBox *)pControl)->GetItem( ((CDXUTListBox *)pControl)->GetSelectedIndex( -1 ) ); break; } case EVENT_LISTBOX_SELECTION: { CDXUTListBox *pListBox = (CDXUTListBox *)pControl; TuiChoiceVector &choices = ret->GetChoices(); NxI32 count = (NxI32)choices.size(); for (NxI32 i=0; i<count; i++) { DXUTListBoxItem *item = pListBox->GetItem(i); TuiChoice &choice = choices[i]; assert(item); if ( item ) { if ( choice.GetState() != item->bSelected ) { choice.SetState(item->bSelected); const char *args[2]; args[0] = choice.GetArg().Get(); if ( choice.GetState() ) args[1] = "true"; else args[1] = "false"; page->ExecuteElement( nControlID-1, 2, args, tui, false ); } } } } } } break; case TT_SLIDER: { CDXUTSlider *slider = (CDXUTSlider *) pControl; NxI32 v = slider->GetValue(); NxF32 fv = ret->GetSliderValue(v); char scratch[512]; sprintf(scratch,"%0.3f", fv ); const char *args[1]; args[0] = scratch; page->ExecuteElement( nControlID-1, 1, args, tui, false ); } break; case TT_COMBO: { CDXUTComboBox *combo = (CDXUTComboBox *) pControl; DXUTComboBoxItem *pItem = combo->GetSelectedItem(); wchar_t *string = pItem->strText; char scratch[512]; wcstombs(scratch, string, 512 ); const char *args[1]; args[0] = scratch; page->ExecuteElement( nControlID-1, 1, args,tui, false ); // now, do we need to hide any items (or show them)? page->OnComboBoxChange( scratch, nControlID-1 ); } break; case TT_BUTTON: case TT_PAGE: page->ExecuteElement( nControlID-1, 0, 0, tui, false ); break; case TT_CHECKBOX: { CDXUTCheckBox *pCheck = (CDXUTCheckBox *)pControl; bool state = pCheck->GetChecked(); const char *args[1]; if ( state ) { args[0] = "true"; } else { args[0] = "false"; } page->ExecuteElement( nControlID-1, 1, args, tui, false ); // now, do we need to hide any items (or show them)? page->OnCheckboxChange( state, nControlID-1 ); } break; } if ( tui ) { if ( ret && ret->GetType() == TT_PAGE ) { // tell the last page it is now exiting TuiElement *exitingPage = tui->GetPage(); if ( exitingPage ) { exitingPage->OnExit( exitingPage ); } tui->SetPage(ret); // tell new page it is now loading TuiElement *loadingPage = tui->GetPage(); if ( loadingPage ) { loadingPage->OnLoad( loadingPage ); } } } } } else { // it's for the console CDXUTEditBox *edit = (CDXUTEditBox *) pControl; switch ( nEvent ) { case EVENT_EDITBOX_STRING: { LPCWSTR text = edit->GetText(); char scratch[1024]; WideToChar(text,scratch,1024); gLog->Display("%s\r\n", scratch); CPARSER.Parse("%s",scratch); edit->SetText(L"",true); } break; case EVENT_EDITBOX_CHANGE: break; default: break; } } }
void CALLBACK onGUIEvent(UINT event, int controlId, CDXUTControl* control, void *userContext) { switch(controlId) { case IDC_TOGGLE_FULLSCREEN: DXUTToggleFullScreen(); break; case IDC_PRESET: if (event == EVENT_COMBOBOX_SELECTION_CHANGED) { SMAA::Preset selected; selected = SMAA::Preset(int(hud.GetComboBox(IDC_PRESET)->GetSelectedData())); onLostDevice(NULL); onResetDevice(DXUTGetD3D9Device(), DXUTGetD3D9BackBufferSurfaceDesc(), NULL); } break; case IDC_ANTIALIASING: if (event == EVENT_CHECKBOX_CHANGED) timer->reset(); break; case IDC_PROFILE: if (event == EVENT_CHECKBOX_CHANGED) { timer->reset(); timer->setEnabled(hud.GetCheckBox(IDC_PROFILE)->GetChecked()); } break; case IDC_THRESHOLD: if (event == EVENT_SLIDER_VALUE_CHANGED) { CDXUTSlider *slider = hud.GetSlider(IDC_THRESHOLD); int min, max; slider->GetRange(min, max); float scale = float(slider->GetValue()) / (max - min); smaa->setThreshold(scale * 0.5f); wstringstream s; s << L"Threshold: " << scale * 0.5f; hud.GetStatic(IDC_THRESHOLD_LABEL)->SetText(s.str().c_str()); } break; case IDC_MAX_SEARCH_STEPS: if (event == EVENT_SLIDER_VALUE_CHANGED) { CDXUTSlider *slider = hud.GetSlider(IDC_MAX_SEARCH_STEPS); int min, max; slider->GetRange(min, max); float scale = float(slider->GetValue()) / (max - min); smaa->setMaxSearchSteps(int(round(scale * 98.0f))); wstringstream s; s << L"Max Search Steps: " << int(round(scale * 98.0f)); hud.GetStatic(IDC_MAX_SEARCH_STEPS_LABEL)->SetText(s.str().c_str()); } break; case IDC_MAX_SEARCH_STEPS_DIAG: if (event == EVENT_SLIDER_VALUE_CHANGED) { CDXUTSlider *slider = hud.GetSlider(IDC_MAX_SEARCH_STEPS_DIAG); int min, max; slider->GetRange(min, max); float scale = float(slider->GetValue()) / (max - min); smaa->setMaxSearchStepsDiag(int(round(scale * 20.0f))); wstringstream s; s << L"Max Diag. Search Steps: " << int(round(scale * 20.0f)); hud.GetStatic(IDC_MAX_SEARCH_STEPS_DIAG_LABEL)->SetText(s.str().c_str()); } break; case IDC_CORNER_ROUNDING: if (event == EVENT_SLIDER_VALUE_CHANGED) { CDXUTSlider *slider = hud.GetSlider(IDC_CORNER_ROUNDING); int min, max; slider->GetRange(min, max); float scale = float(slider->GetValue()) / (max - min); smaa->setCornerRounding(scale * 100.0f); wstringstream s; s << L"Corner Rounding: " << scale * 100.0f; hud.GetStatic(IDC_CORNER_ROUNDING_LABEL)->SetText(s.str().c_str()); } break; } }
//-------------------------------------------------------------------------------------- // Handles the GUI events //-------------------------------------------------------------------------------------- void CALLBACK OnGUIEvent(UINT nEvent, INT nControlID, CDXUTControl* /*pControl*/, void* /*pUserContext*/) { switch (nControlID) { case IDC_TOGGLEFULLSCREEN: DXUTToggleFullScreen(); break; case IDC_TOGGLEWARP: DXUTToggleWARP(); break; case IDC_CHANGEDEVICE: g_D3DSettingsDlg.SetActive(!g_D3DSettingsDlg.IsActive()); break; break; break; case IDC_FIT_TO_CASCADE: g_CascadedShadow.m_eSelectedCascadesFit = (FIT_PROJECTION_TO_CASCADES)PtrToUlong(g_FitToCascadesCombo->GetSelectedData()); break; case IDC_FIT_TO_NEARFAR: { g_CascadedShadow.m_eSelectedNearFarFit = (FIT_TO_NEAR_FAR)PtrToUlong(g_FitToNearFarCombo->GetSelectedData()); if (g_CascadedShadow.m_eSelectedNearFarFit == FIT_NEARFAR_PANCAKING) { g_CascadedShadow.m_eSelectedCascadeSelection = CASCADE_SELECTION_INTERVAL; g_CascadeSelectionCombo->SetSelectedByData(ULongToPtr(CASCADE_SELECTION_INTERVAL)); } } break; case IDC_CASCADE_SELECT: { static int iSaveLastCascadeValue = 100; if ((CASCADE_SELECTION)PtrToUlong(g_CascadeSelectionCombo->GetSelectedData()) == CASCADE_SELECTION_MAP) { if ((FIT_TO_NEAR_FAR)PtrToUlong(g_FitToNearFarCombo->GetSelectedData()) == FIT_NEARFAR_PANCAKING) { g_FitToNearFarCombo->SetSelectedByData(ULongToPtr(FIT_NEARFAR_SCENE_AABB)); g_CascadedShadow.m_eSelectedNearFarFit = FIT_NEARFAR_SCENE_AABB; } g_CascadedShadow.m_iCascadePartitionsZeroToOne[g_CascadeConfig.m_nCascadeLevels - 1] = iSaveLastCascadeValue; } else { iSaveLastCascadeValue = g_CascadedShadow.m_iCascadePartitionsZeroToOne[g_CascadeConfig.m_nCascadeLevels - 1]; g_CascadedShadow.m_iCascadePartitionsZeroToOne[g_CascadeConfig.m_nCascadeLevels - 1] = 100; } g_CascadedShadow.m_eSelectedCascadeSelection = (CASCADE_SELECTION)PtrToUlong(g_CascadeSelectionCombo->GetSelectedData()); g_HUD.GetSlider(IDC_CASCADELEVEL1 + g_CascadeConfig.m_nCascadeLevels - 1)->SetValue( g_CascadedShadow.m_iCascadePartitionsZeroToOne[g_CascadeConfig.m_nCascadeLevels - 1]); WCHAR label[16]; swprintf_s(label, L"L%d: %d", g_CascadeConfig.m_nCascadeLevels, g_CascadedShadow.m_iCascadePartitionsZeroToOne[g_CascadeConfig.m_nCascadeLevels - 1]); g_HUD.GetStatic(IDC_CASCADELEVEL1TEXT + g_CascadeConfig.m_nCascadeLevels - 1)->SetText(label); } break; case IDC_MOVE_LIGHT_IN_TEXEL_INC: g_bMoveLightTexelSize = !g_bMoveLightTexelSize; g_CascadedShadow.m_bMoveLightTexelSize = g_bMoveLightTexelSize; break; case IDC_TOGGLEVISUALIZECASCADES: g_bVisualizeCascades = !g_bVisualizeCascades; break; case IDC_PCF_SIZE: { INT PCFSize = g_HUD.GetSlider(IDC_PCF_SIZE)->GetValue(); PCFSize *= 2; PCFSize -= 1; WCHAR desc[256]; swprintf_s(desc, L"PCF Blur: %d ", PCFSize); g_HUD.GetStatic(IDC_PCF_SIZETEXT)->SetText(desc); g_CascadedShadow.m_iPCFBlurSize = PCFSize; } break; case IDC_PCF_OFFSET_SIZE: { INT offset = g_HUD.GetSlider(IDC_PCF_OFFSET_SIZE)->GetValue(); FLOAT useoffset = (FLOAT)offset * 0.001f; WCHAR desc[256]; swprintf_s(desc, L" Offset: %0.03f", useoffset); g_HUD.GetStatic(IDC_PCF_OFFSET_SIZETEXT)->SetText(desc); g_CascadedShadow.m_fPCFOffset = useoffset; } break; case IDC_BLEND_BETWEEN_MAPS_CHECK: if (g_HUD.GetCheckBox(IDC_BLEND_BETWEEN_MAPS_CHECK)->GetChecked()) g_CascadedShadow.m_iBlurBetweenCascades = 1; else g_CascadedShadow.m_iBlurBetweenCascades = 0; break; case IDC_BLEND_MAPS_SLIDER: { INT val = g_HUD.GetSlider(IDC_BLEND_MAPS_SLIDER)->GetValue(); g_CascadedShadow.m_fBlurBetweenCascadesAmount = (float)val * 0.005f; WCHAR dta[256]; swprintf_s(dta, L"Cascade Blur %0.03f", g_CascadedShadow.m_fBlurBetweenCascadesAmount); g_HUD.GetCheckBox(IDC_BLEND_BETWEEN_MAPS_CHECK)->SetText(dta); } break; case IDC_TOGGLE_DERIVATIVE_OFFSET: { if (g_CascadedShadow.m_iDerivativeBasedOffset == 0) g_CascadedShadow.m_iDerivativeBasedOffset = 1; else g_CascadedShadow.m_iDerivativeBasedOffset = 0; } break; case IDC_BUFFER_SIZE: { INT value = 32 * g_HUD.GetSlider(IDC_BUFFER_SIZE)->GetValue(); INT max = 8192 / g_CascadeConfig.m_nCascadeLevels; if (value > max) { value = max; g_HUD.GetSlider(IDC_BUFFER_SIZE)->SetValue(value / 32); } WCHAR desc[256]; swprintf_s(desc, L"Texture Size: %d ", value); g_HUD.GetStatic(IDC_BUFFER_SIZETEXT)->SetText(desc); //Only tell the app to recreate buffers once the user is through moving the slider. if (nEvent == EVENT_SLIDER_VALUE_CHANGED_UP) { g_CascadeConfig.m_iBufferSize = value; } } break; case IDC_SELECTED_SCENE: { SCENE_SELECTION ss = (SCENE_SELECTION)PtrToUlong(g_SceneSelectCombo->GetSelectedData()); if (ss == POWER_PLANT_SCENE) { g_pSelectedMesh = &g_MeshPowerPlant; } else if (ss == TEST_SCENE) { g_pSelectedMesh = &g_MeshTestScene; } DestroyD3DComponents(); CreateD3DComponents(DXUTGetD3D11Device()); UpdateViewerCameraNearFar(); } case IDC_SELECTED_CAMERA: { g_CascadedShadow.m_eSelectedCamera = (CAMERA_SELECTION) (g_CameraSelectCombo->GetSelectedIndex()); if (g_CascadedShadow.m_eSelectedCamera < 1) { g_pActiveCamera = &g_ViewerCamera; } else { g_pActiveCamera = &g_LightCamera; } } break; case IDC_CASCADELEVELS: { INT ind = 1 + g_CascadeLevelsCombo->GetSelectedIndex(); g_CascadeConfig.m_nCascadeLevels = ind; for (INT index = 0; index < ind; ++index) { g_HUD.GetStatic(IDC_CASCADELEVEL1TEXT + index)->SetVisible(true); g_HUD.GetSlider(IDC_CASCADELEVEL1 + index)->SetVisible(true); } for (int index = ind; index < MAX_CASCADES; ++index) { g_HUD.GetStatic(IDC_CASCADELEVEL1TEXT + index)->SetVisible(false); g_HUD.GetSlider(IDC_CASCADELEVEL1 + index)->SetVisible(false); } INT value = 32 * g_HUD.GetSlider(IDC_BUFFER_SIZE)->GetValue(); INT max = 8192 / g_CascadeConfig.m_nCascadeLevels; if (value > max) { WCHAR desc[256]; value = max; swprintf_s(desc, L"Texture Size: %d ", value); g_HUD.GetStatic(IDC_BUFFER_SIZETEXT)->SetText(desc); g_HUD.GetSlider(IDC_BUFFER_SIZE)->SetValue(value / 32); g_CascadeConfig.m_iBufferSize = value; } // update the selected camera based on these changes. INT selected = g_CameraSelectCombo->GetSelectedIndex(); WCHAR dta[60]; g_CameraSelectCombo->RemoveAllItems(); swprintf_s(dta, L"Eye Camera %ld", EYE_CAMERA + 1); g_CameraSelectCombo->AddItem(dta, ULongToPtr(EYE_CAMERA)); swprintf_s(dta, L"Light Camera %ld", LIGHT_CAMERA + 1); g_CameraSelectCombo->AddItem(dta, ULongToPtr(LIGHT_CAMERA)); for (int index = 0; index < g_CascadeConfig.m_nCascadeLevels; ++index) { swprintf_s(dta, L"Cascade Cam %d", index + 1); g_CameraSelectCombo->AddItem(dta, ULongToPtr(ORTHO_CAMERA1 + index)); } if (selected - 1 >= ind) { selected = ind + 1; } g_CameraSelectCombo->SetSelectedByIndex(selected); g_CascadedShadow.m_eSelectedCamera = (CAMERA_SELECTION) (g_CameraSelectCombo->GetSelectedIndex()); if (g_CascadedShadow.m_eSelectedCamera < 1) { g_pActiveCamera = &g_ViewerCamera; } else { g_pActiveCamera = &g_LightCamera; } } break; case IDC_DEPTHBUFFERFORMAT: { SHADOW_TEXTURE_FORMAT sbt = (SHADOW_TEXTURE_FORMAT)PtrToUlong(g_DepthBufferFormatCombo->GetSelectedData()); g_CascadeConfig.m_ShadowBufferFormat = sbt; } break; case IDC_CASCADELEVEL1: case IDC_CASCADELEVEL2: case IDC_CASCADELEVEL3: case IDC_CASCADELEVEL4: case IDC_CASCADELEVEL5: case IDC_CASCADELEVEL6: case IDC_CASCADELEVEL7: case IDC_CASCADELEVEL8: { INT ind = nControlID - IDC_CASCADELEVEL1; INT move = g_HUD.GetSlider(nControlID)->GetValue(); CDXUTSlider* selecteSlider; CDXUTStatic* selectedStatic; WCHAR label[16]; for (int index = 0; index < ind; ++index) { selecteSlider = g_HUD.GetSlider(IDC_CASCADELEVEL1 + index); INT sVal = selecteSlider->GetValue(); if (move < sVal) { selecteSlider->SetValue(move); selectedStatic = g_HUD.GetStatic(IDC_CASCADELEVEL1TEXT + index); swprintf_s(label, L"L%d: %d", index + 1, move); selectedStatic->SetText(label); g_CascadedShadow.m_iCascadePartitionsZeroToOne[index] = move; } } for (int index = ind; index < MAX_CASCADES; ++index) { selecteSlider = g_HUD.GetSlider(IDC_CASCADELEVEL1 + index); INT sVal = selecteSlider->GetValue(); if (move >= sVal) { selecteSlider->SetValue(move); selectedStatic = g_HUD.GetStatic(IDC_CASCADELEVEL1TEXT + index); swprintf_s(label, L"L%d: %d", index + 1, move); selectedStatic->SetText(label); g_CascadedShadow.m_iCascadePartitionsZeroToOne[index] = move; } } } break; } }