@@ -138,6 +138,22 @@ OptionsView::OptionsView() : ui::Window(ui::Point(-1, -1), ui::Point(320, 340))
138138 scrollPanel->AddChild (label);
139139 currentY += 20 ;
140140 }
141+ { // Vorticity coefficient setting
142+ vorticityCoeff = new ui::Textbox (ui::Point (Size.X -95 , currentY), ui::Point (80 , 16 ));
143+ vorticityCoeff->SetActionCallback ({ [this ] {
144+ UpdateVorticityCoeff (vorticityCoeff->GetText (), false );
145+ } });
146+ vorticityCoeff->SetDefocusCallback ({ [this ] {
147+ UpdateVorticityCoeff (vorticityCoeff->GetText (), true );
148+ }});
149+ vorticityCoeff->SetLimit (9 );
150+ scrollPanel->AddChild (vorticityCoeff);
151+ auto *label = new ui::Label (ui::Point (8 , currentY), ui::Point (Size.X -105 , 16 ), " Vorticity confinement" );
152+ label->Appearance .HorizontalAlign = ui::Appearance::AlignLeft;
153+ label->Appearance .VerticalAlign = ui::Appearance::AlignMiddle;
154+ scrollPanel->AddChild (label);
155+ currentY += 20 ;
156+ }
141157 class GravityWindow : public ui ::Window
142158 {
143159 void OnTryExit (ExitMethod method) override
@@ -430,6 +446,13 @@ void OptionsView::AmbientAirTempToTextBox(float airTemp)
430446 ambientAirTemp->SetText (sb.Build ());
431447}
432448
449+ void OptionsView::VorticityCoeffToTextBox (float vorticity)
450+ {
451+ StringBuilder sb;
452+ sb << Format::Precision (2 ) << vorticity;
453+ vorticityCoeff->SetText (sb.Build ());
454+ }
455+
433456void OptionsView::UpdateStartupRequestStatus ()
434457{
435458 switch (Client::Ref ().GetStartupRequestStatus ())
@@ -502,6 +525,47 @@ void OptionsView::UpdateAirTemp(String temp, bool isDefocus)
502525 UpdateAmbientAirTempPreview (airTemp, isValid);
503526}
504527
528+ void OptionsView::UpdateVorticityCoeff (String vort, bool isDefocus)
529+ {
530+ // Parse vorticity and determine validity
531+ float vorticity = 0 ;
532+ bool isValid;
533+ try
534+ {
535+ vorticity = vort.ToNumber <float >();
536+ isValid = true ;
537+ }
538+ catch (const std::exception &ex)
539+ {
540+ isValid = false ;
541+ }
542+
543+ // While defocusing, correct out of range vorticity and empty textboxes
544+ if (isDefocus)
545+ {
546+ if (vort.empty ())
547+ {
548+ isValid = true ;
549+ vorticity = 0 .0f ;
550+ }
551+ else if (!isValid)
552+ return ;
553+ else if (vorticity < 0 .0f )
554+ vorticity = 0 .0f ;
555+ else if (vorticity > 1 .0f )
556+ vorticity = 1 .0f ;
557+
558+ VorticityCoeffToTextBox (vorticity);
559+ }
560+ // Out of range vorticities are invalid, preview should go away
561+ else if (isValid && (vorticity < 0 .0f || vorticity > 1 .0f ))
562+ isValid = false ;
563+
564+ // If valid, set vorticity
565+ if (isValid)
566+ c->SetVorticityCoeff (vorticity);
567+ }
568+
505569void OptionsView::NotifySettingsChanged (OptionsModel * sender)
506570{
507571 temperatureScale->SetOption (sender->GetTemperatureScale ()); // has to happen before AmbientAirTempToTextBox is called
@@ -517,6 +581,11 @@ void OptionsView::NotifySettingsChanged(OptionsModel * sender)
517581 UpdateAmbientAirTempPreview (airTemp, true );
518582 AmbientAirTempToTextBox (airTemp);
519583 }
584+ // Same for vorticity
585+ if (!vorticityCoeff->IsFocused ())
586+ {
587+ VorticityCoeffToTextBox (sender->GetVorticityCoeff ());
588+ }
520589 gravityMode->SetOption (sender->GetGravityMode ());
521590 customGravityX = sender->GetCustomGravityX ();
522591 customGravityY = sender->GetCustomGravityY ();
0 commit comments