Forráskód Böngészése

Failed attempt to fix opacity input field

Equbuxu 3 éve
szülő
commit
8b6cca4fee

+ 5 - 1
src/PixiEditor/Helpers/Converters/MultiplyConverter.cs

@@ -15,7 +15,11 @@ internal class MultiplyConverter : SingleInstanceConverter<MultiplyConverter>
 
     public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
     {
-        return 0;
+        double? actuallyValue = NumberToDouble(value);
+        double? factor = NumberToDouble(parameter);
+        if (actuallyValue is null || factor is null)
+            return DependencyProperty.UnsetValue;
+        return actuallyValue / factor;
     }
 
     private double? NumberToDouble(object number)

+ 8 - 6
src/PixiEditor/ViewModels/SubViewModels/Document/StructureMemberViewModel.cs

@@ -122,12 +122,14 @@ internal abstract class StructureMemberViewModel : INotifyPropertyChanged
     public float OpacityBindable
     {
         get => opacity;
-        // this is stupid. This setter shouldn't actually exist, but it has to because the NumberInput control is badly designed.
-        // You can't bind it's value using a OneWay binding, because it gets overwritten by NumberInput internally when it assigns something to Value
-        // This doesn't happen with TwoWay bindings because they behave differently and forward the value you set instead of getting replaced
-        // So really I just need a OneWay binding, but I'm forced to use a TwoWay binding with a setter
-        // The binding is in LayersManager's opacity field btw.
-        set { }
+        set
+        {
+            if (Document.UpdateableChangeActive)
+                return;
+            Helpers.ActionAccumulator.AddFinishedActions(
+                new StructureMemberOpacity_Action(GuidValue, value),
+                new EndStructureMemberOpacity_Action());
+        }
     }
 
     public StructureMemberSelectionType Selection { get; set; }

+ 1 - 1
src/PixiEditor/Views/UserControls/Layers/LayersManager.xaml.cs

@@ -53,7 +53,7 @@ internal partial class LayersManager : UserControl
     {
         if (ActiveDocument?.SelectedStructureMember is null)
             return;
-        ActiveDocument.SetMemberOpacity(ActiveDocument.SelectedStructureMember.GuidValue, numberInput.Value / 100f);
+        //ActiveDocument.SetMemberOpacity(ActiveDocument.SelectedStructureMember.GuidValue, numberInput.Value / 100f);
 
         // does anyone know why this is here?
         ShortcutController.UnblockShortcutExecutionAll();

+ 5 - 3
src/PixiEditor/Views/UserControls/NumberInput.xaml.cs

@@ -97,19 +97,21 @@ internal partial class NumberInput : UserControl
     {
         int step = e.Delta / 100;
 
+        float newValue = Value;
         if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
         {
             float multiplier = (Max - Min) * 0.1f;
-            Value += step * multiplier;
+            newValue += step * multiplier;
         }
         else if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
         {
-            Value += step / 2f;
+            newValue += step / 2f;
         }
         else
         {
-            Value += step;
+            newValue += step;
         }
+        Value = (float)Math.Round(Math.Clamp(newValue, Min, Max), Decimals);
 
         OnScrollAction?.Invoke();
     }