Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLarry Ewing <lewing@xamarin.com>2018-05-10 02:31:40 +0300
committerLarry Ewing <lewing@microsoft.com>2018-07-16 22:05:49 +0300
commita7fb38a78a5af820c8f41c8e6db676b30df43cfb (patch)
tree509c7b60f941dd6b7beeecc9920af2caa3328b94 /Xamarin.PropertyEditing.Mac
parent4d0cf0452d16bc17079febeec2a3fe653f4eed45 (diff)
Move the value updates to the layout step
Diffstat (limited to 'Xamarin.PropertyEditing.Mac')
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs2
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs7
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentEditor.cs6
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentViewController.cs4
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/ColorEditorLayer.cs43
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushLayer.cs4
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/CommonGradientBrushLayer.cs2
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/HistoryLayer.cs64
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/HueLayer.cs49
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialBrushEditorViewController.cs4
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialColorLayer.cs28
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialView.cs12
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/NotifyingViewAdaptor.cs1
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/ShadeLayer.cs54
-rw-r--r--Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs113
15 files changed, 234 insertions, 159 deletions
diff --git a/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs
index f0964b1..ab60a7d 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/BrushEditorControl.cs
@@ -30,7 +30,7 @@ namespace Xamarin.PropertyEditing.Mac
{
if (Popover == null)
return;
- //Popover.SetAppearance (PropertyEditorPanel.ThemeManager.CurrentAppearance);
+
Popover?.Show (new CGRect (20, this.Frame.Height / 2 - 2.5, 5, 5), this, NSRectEdge.MinYEdge);
}
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs
index f56f787..786e509 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/BrushTabViewController.cs
@@ -10,15 +10,14 @@ namespace Xamarin.PropertyEditing.Mac
{
class BrushTabViewController : PropertyTabViewController<BrushPropertyViewModel>
{
- Dictionary<CommonBrushType, int> BrushTypeTable = new Dictionary<CommonBrushType, int> ();
-
- bool inhibitSelection;
-
public BrushTabViewController ()
{
PreferredContentSize = new CGSize (300, 230);
}
+ Dictionary<CommonBrushType, int> BrushTypeTable = new Dictionary<CommonBrushType, int> ();
+ bool inhibitSelection;
+
public override void OnViewModelChanged (BrushPropertyViewModel oldModel)
{
inhibitSelection = true;
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentEditor.cs
index b27ee13..eb06942 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentEditor.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentEditor.cs
@@ -4,8 +4,6 @@ using System.Linq;
using AppKit;
using CoreAnimation;
using CoreGraphics;
-using Foundation;
-using Xamarin.PropertyEditing.Drawing;
using Xamarin.PropertyEditing.ViewModels;
namespace Xamarin.PropertyEditing.Mac
@@ -116,6 +114,7 @@ namespace Xamarin.PropertyEditing.Mac
var color = ViewModel.Color;
var editor = sender as ComponentSpinEditor;
ViewModel.Color = editor.ComponentEditor.UpdateColorFromValue (color, editor.Value);
+ ViewModel.CommitLastColor ();
}
protected override void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
@@ -188,6 +187,9 @@ namespace Xamarin.PropertyEditing.Mac
public override void MouseUp(NSEvent theEvent)
{
+ if (activeChannel != null)
+ ViewModel.CommitLastColor ();
+
activeChannel = null;
base.MouseUp(theEvent);
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentViewController.cs
index c26c776..65f3246 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentViewController.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorComponentViewController.cs
@@ -16,6 +16,8 @@ namespace Xamarin.PropertyEditing.Mac
this.EditorType = type;
}
+ public ChannelEditorType EditorType { get; }
+
public override void OnViewModelChanged (SolidBrushViewModel oldModel)
{
base.OnViewModelChanged (oldModel);
@@ -30,8 +32,6 @@ namespace Xamarin.PropertyEditing.Mac
}
}
- public ChannelEditorType EditorType { get; }
-
public override void LoadView ()
{
View = editor = new ColorComponentEditor (this.EditorType);
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorEditorLayer.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorEditorLayer.cs
index 752f937..1ec1025 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorEditorLayer.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/ColorEditorLayer.cs
@@ -1,6 +1,7 @@
using System;
using CoreAnimation;
using CoreGraphics;
+using Foundation;
namespace Xamarin.PropertyEditing.Mac
{
@@ -10,11 +11,47 @@ namespace Xamarin.PropertyEditing.Mac
{
}
- public ColorEditorLayer (IntPtr handle) : base (handle)
+ public override NSObject ActionForKey(string eventKey)
+ {
+ return null;
+ }
+
+ public ColorEditorLayer (IntPtr handle) : base (handle)
+ {
+ }
+
+ abstract public void Commit (EditorInteraction interaction);
+ abstract public void UpdateFromModel (EditorInteraction interaction);
+ abstract public void UpdateFromLocation (EditorInteraction interaction, CGPoint location);
+ }
+
+ class CAGradientLayerQuick : CAGradientLayer {
+ public CAGradientLayerQuick ()
{
}
- abstract public void UpdateFromModel (EditorInteraction viewModel);
- abstract public void UpdateFromLocation (EditorInteraction viewModel, CGPoint location);
+ public CAGradientLayerQuick (IntPtr handle) : base (handle)
+ {
+ }
+
+ public override NSObject ActionForKey (string eventKey)
+ {
+ return null;
+ }
+ }
+
+ class CALayerQuick : CALayer {
+ public CALayerQuick ()
+ {
+ }
+
+ public CALayerQuick (IntPtr handle) : base (handle)
+ {
+ }
+
+ public override NSObject ActionForKey (string eventKey)
+ {
+ return null;
+ }
}
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushLayer.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushLayer.cs
index 1325567..e49e560 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushLayer.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonBrushLayer.cs
@@ -66,8 +66,8 @@ namespace Xamarin.PropertyEditing.Mac
public override void LayoutSublayers ()
{
base.LayoutSublayers ();
- BrushLayer.Frame = new CGRect (0, 0, Frame.Width, Frame.Height);
- Contents = DrawingExtensions.GenerateCheckerboard (Frame);
+ BrushLayer.Frame = Bounds;
+ Contents = DrawingExtensions.GenerateCheckerboard (Bounds);
}
public NSImage RenderPreview ()
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonGradientBrushLayer.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonGradientBrushLayer.cs
index 5b18fb9..53a8885 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonGradientBrushLayer.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/CommonGradientBrushLayer.cs
@@ -12,7 +12,7 @@ namespace Xamarin.PropertyEditing.Mac
{
}
- public CommonGradientBrushLayer (IntPtr handle) : base ()
+ public CommonGradientBrushLayer (IntPtr handle) : base (handle)
{
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/HistoryLayer.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/HistoryLayer.cs
index c29727e..4b86b1d 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/HistoryLayer.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/HistoryLayer.cs
@@ -11,18 +11,29 @@ namespace Xamarin.PropertyEditing.Mac
public HistoryLayer ()
{
- Clip.AddSublayer (Previous);
- Clip.AddSublayer (Current);
- AddSublayer (Clip);
+ clip.AddSublayer (previous);
+ clip.AddSublayer (current);
+ AddSublayer (clip);
+ AddSublayer (lastClip);
+ lastClip.AddSublayer (last);
}
public HistoryLayer (IntPtr handle) : base (handle)
{
}
- readonly CALayer Previous = new CALayer ();
- readonly CALayer Current = new CALayer ();
- readonly CALayer Clip = new CALayer () {
+ readonly CALayer previous = new CALayerQuick ();
+ readonly CALayer current = new CALayerQuick ();
+ readonly CALayer last = new CALayerQuick ();
+
+ readonly CALayer lastClip = new CALayer {
+ BorderWidth = 1,
+ CornerRadius = BorderRadius,
+ BorderColor = new CGColor (.5f, .5f, .5f, .5f),
+ MasksToBounds = true
+ };
+
+ readonly CALayer clip = new CALayer {
BorderWidth = 1,
CornerRadius = BorderRadius,
BorderColor = new CGColor (.5f, .5f, .5f, .5f),
@@ -33,30 +44,43 @@ namespace Xamarin.PropertyEditing.Mac
{
base.LayoutSublayers ();
- Clip.Frame = new CGRect (
- Margin,
- Margin,
- Frame.Width - 2 * Margin,
- Frame.Height - 2 * Margin);
+ lastClip.Frame = new CGRect (
+ Bounds.Right - Bounds.Height,
+ 0,
+ Bounds.Height,
+ Bounds.Height).Inset (Margin, Margin);
+
+ clip.Frame = new CGRect (
+ 0,
+ 0,
+ Bounds.Width - Bounds.Height + Margin,
+ Bounds.Height).Inset (Margin, Margin);
- Clip.Contents = DrawingExtensions.GenerateCheckerboard (Clip.Frame);
- var width = Clip.Frame.Width / 2;
+ clip.Contents = DrawingExtensions.GenerateCheckerboard (clip.Bounds);
+ lastClip.Contents = DrawingExtensions.GenerateCheckerboard (last.Bounds);
+ last.Frame = lastClip.Bounds;
- Previous.Frame = new CGRect (0, 0, width, Clip.Frame.Height);
- Current.Frame = new CGRect (width, 0, width, Clip.Frame.Height);
+ var width = clip.Frame.Width / 2;
+ previous.Frame = new CGRect (0, 0, width, clip.Frame.Height);
+ current.Frame = new CGRect (width, 0, width, clip.Frame.Height);
}
public override void UpdateFromModel (EditorInteraction interaction)
{
LayoutIfNeeded ();
- Current.BackgroundColor = interaction.Color.ToCGColor ();
- Previous.BackgroundColor = interaction.LastColor.ToCGColor ();
+ current.BackgroundColor = interaction.Color.ToCGColor ();
+ previous.BackgroundColor = interaction.ViewModel.InitialColor.ToCGColor ();
+ last.BackgroundColor = interaction.LastColor.ToCGColor ();
}
public override void UpdateFromLocation (EditorInteraction interaction, CGPoint location)
{
- if (Previous == HitTest (location))
- interaction.Color = interaction.LastColor;
+ if (previous == HitTest (location))
+ interaction.Color = interaction.ViewModel.InitialColor;
}
- }
+
+ public override void Commit (EditorInteraction interaction)
+ {
+ }
+ }
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/HueLayer.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/HueLayer.cs
index 34dc034..b5e3cc4 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/HueLayer.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/HueLayer.cs
@@ -15,8 +15,8 @@ namespace Xamarin.PropertyEditing.Mac
public CGColor GripColor
{
- get => Grip.BorderColor;
- set => Grip.BorderColor = value;
+ get => grip.BorderColor;
+ set => grip.BorderColor = value;
}
public HueLayer ()
@@ -30,12 +30,12 @@ namespace Xamarin.PropertyEditing.Mac
void Initialize ()
{
- hueEditor.UpdateGradientLayer (Colors, new CommonColor (0, 255, 0));
- AddSublayer (Colors);
- AddSublayer (Grip);
+ hueEditor.UpdateGradientLayer (colors, new CommonColor (0, 255, 0));
+ AddSublayer (colors);
+ AddSublayer (grip);
}
- readonly CAGradientLayer Colors = new CAGradientLayer {
+ readonly CAGradientLayer colors = new CAGradientLayer {
BorderColor = new CGColor (.5f, .5f, .5f, .5f),
StartPoint = new CGPoint (0, 1),
EndPoint = new CGPoint (0, 0),
@@ -43,7 +43,7 @@ namespace Xamarin.PropertyEditing.Mac
CornerRadius = BorderRadius,
};
- readonly CALayer Grip = new CALayer {
+ readonly CALayer grip = new CALayerQuick {
BorderColor = NSColor.Text.CGColor,
BorderWidth = 2,
CornerRadius = GripRadius,
@@ -55,42 +55,43 @@ namespace Xamarin.PropertyEditing.Mac
LayoutIfNeeded ();
var color = interaction.Color;
- if (c == color)
- return;
-
- var loc = hueEditor.LocationFromColor (Colors, color);
- Grip.Frame = new CGRect (1, loc.Y - Grip.Frame.Height / 2f, Grip.Frame.Width, Grip.Frame.Height);
+
+ var loc = hueEditor.LocationFromColor (colors, color);
+ grip.Frame = new CGRect (1, loc.Y - grip.Frame.Height / 2f, grip.Frame.Width, grip.Frame.Height);
}
public override void UpdateFromLocation (EditorInteraction interaction, CGPoint location)
{
- var clos = Math.Min (Colors.Frame.Height, Math.Max (0, location.Y - Colors.Frame.Y));
+ var clos = Math.Min (colors.Frame.Height, Math.Max (0, location.Y - colors.Frame.Y));
- Grip.Frame = new CGRect (
+ grip.Frame = new CGRect (
1,
- clos + Colors.Frame.Y - Grip.Frame.Height / 2f,
+ clos + colors.Frame.Y - grip.Frame.Height / 2f,
Frame.Width - 2,
2 * GripRadius);
- var hue = (1 - clos / Colors.Frame.Height) * 360;
-
if (interaction == null)
return;
var color = interaction.Color;
c = interaction.Color = hueEditor.UpdateColorFromLocation (
- Colors,
- interaction.Color,
+ colors,
+ color,
location);
}
- public override void LayoutSublayers ()
+ public override void Commit(EditorInteraction viewModel)
+ {
+ viewModel.ViewModel.CommitLastColor ();
+ }
+
+ public override void LayoutSublayers ()
{
base.LayoutSublayers ();
- Colors.Frame = Bounds.Inset (2, 2);
- Grip.Frame = new CGRect (
- Grip.Frame.X,
- Grip.Frame.Y,
+ colors.Frame = Bounds.Inset (2, 2);
+ grip.Frame = new CGRect (
+ grip.Frame.X,
+ grip.Frame.Y,
Frame.Width - 2,
2 * GripRadius);
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialBrushEditorViewController.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialBrushEditorViewController.cs
index cde9f35..d38220e 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialBrushEditorViewController.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialBrushEditorViewController.cs
@@ -9,13 +9,13 @@ namespace Xamarin.PropertyEditing.Mac
{
class MaterialBrushEditorViewController : PropertyViewController <BrushPropertyViewModel>
{
- MaterialView materialEditor;
-
public MaterialBrushEditorViewController ()
{
PreferredContentSize = new CGSize (200, 230);
}
+ MaterialView materialEditor;
+
public override void OnPropertyChanged (object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName) {
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialColorLayer.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialColorLayer.cs
index fd8f07c..52785de 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialColorLayer.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialColorLayer.cs
@@ -8,10 +8,10 @@ namespace Xamarin.PropertyEditing.Mac
{
public MaterialColorLayer ()
{
- AddSublayer (Selection);
+ AddSublayer (selection);
}
- readonly CATextLayer Selection = new CATextLayer () {
+ readonly CATextLayer selection = new CATextLayer () {
CornerRadius = 3
};
@@ -26,14 +26,14 @@ namespace Xamarin.PropertyEditing.Mac
}
}
- CommonColor materialColor;
+ CommonColor backgroundColor;
public new CommonColor BackgroundColor
{
- get => materialColor;
+ get => backgroundColor;
set
{
- materialColor = value;
- base.BackgroundColor = materialColor.ToCGColor ();
+ backgroundColor = value;
+ base.BackgroundColor = backgroundColor.ToCGColor ();
}
}
@@ -54,14 +54,14 @@ namespace Xamarin.PropertyEditing.Mac
{
base.LayoutSublayers ();
- Selection.String = text;
- Selection.Frame = Bounds.Inset (3, 3);
- Selection.BorderWidth = isSelected ? 2 : 0;
- Selection.BorderColor = ForegroundColor;
- Selection.ForegroundColor = ForegroundColor;
- Selection.FontSize = FontSize;
- Selection.ContentsScale = ContentsScale;
- Selection.TextAlignmentMode = TextAlignmentMode;
+ selection.String = text;
+ selection.Frame = Bounds.Inset (3, 3);
+ selection.BorderWidth = isSelected ? 2 : 0;
+ selection.BorderColor = ForegroundColor;
+ selection.ForegroundColor = ForegroundColor;
+ selection.FontSize = FontSize;
+ selection.ContentsScale = ContentsScale;
+ selection.TextAlignmentMode = TextAlignmentMode;
}
}
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialView.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialView.cs
index d63bc7a..785d790 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialView.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/MaterialView.cs
@@ -12,7 +12,7 @@ namespace Xamarin.PropertyEditing.Mac
{
public override bool IsFlipped => true;
- readonly string[] ColorNames = {
+ static readonly string[] ColorNames = {
"50",
"100",
"200",
@@ -25,19 +25,19 @@ namespace Xamarin.PropertyEditing.Mac
"900"
};
- readonly string[] AccentNames = {
+ static readonly string[] AccentNames = {
"A100",
"A200",
"A400",
"A700"
};
- readonly string[] BlackWhite = {
+ static readonly string[] BlackWhite = {
"White",
"Black"
};
- public MaterialView () : base ()
+ public MaterialView ()
{
Initialize ();
}
@@ -53,6 +53,9 @@ namespace Xamarin.PropertyEditing.Mac
get => viewModel;
set
{
+ if (viewModel == value)
+ return;
+
viewModel = value;
NeedsLayout = true;
}
@@ -137,7 +140,6 @@ namespace Xamarin.PropertyEditing.Mac
BorderColor = new CGColor (.5f, .5f, .5f, .5f),
BorderWidth = 1
};
-
Layer.AddSublayer (normal);
foreach (var n in MaterialDesign.NormalColorScale.Zip (names, (c, name) => new { Name = name, Color = c.Value })) {
var l = CreateLayer (n.Name, n.Color);
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/NotifyingViewAdaptor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/NotifyingViewAdaptor.cs
index 92f3388..75a9bea 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/NotifyingViewAdaptor.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/NotifyingViewAdaptor.cs
@@ -3,7 +3,6 @@ using System.ComponentModel;
namespace Xamarin.PropertyEditing.Mac
{
-
interface INotifyingListner<T> where T : NotifyingObject
{
void OnViewModelChanged (T oldModel);
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/ShadeLayer.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/ShadeLayer.cs
index dc321f6..d03f758 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/ShadeLayer.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/ShadeLayer.cs
@@ -17,12 +17,12 @@ namespace Xamarin.PropertyEditing.Mac
public ShadeLayer ()
{
- AddSublayer (Saturation);
- Saturation.AddSublayer (Brightness);
- AddSublayer (Grip);
+ AddSublayer (saturationLayer);
+ saturationLayer.AddSublayer (brightnessLayer);
+ AddSublayer (grip);
float innerRadius = GripRadius - 1;
- Grip.AddSublayer (new CALayer {
+ grip.AddSublayer (new CALayer {
BorderWidth = 1,
BorderColor = new CGColor (0, 0, 0),
Frame = new CGRect (
@@ -38,13 +38,13 @@ namespace Xamarin.PropertyEditing.Mac
{
}
- CALayer Grip = new CALayer {
+ readonly CALayer grip = new CALayerQuick {
BorderColor = new CGColor (1, 1, 1),
BorderWidth = 1,
CornerRadius = GripRadius,
};
- CAGradientLayer Brightness = new CAGradientLayer {
+ readonly CAGradientLayer brightnessLayer = new CAGradientLayerQuick {
Colors = new[] {
new CGColor (0f, 0f, 0f, 1f),
new CGColor (0f, 0f, 0f, 0f)
@@ -52,11 +52,12 @@ namespace Xamarin.PropertyEditing.Mac
CornerRadius = BorderRadius,
};
- CAGradientLayer Saturation = new CAGradientLayer {
+ readonly CAGradientLayer saturationLayer = new CAGradientLayerQuick {
Colors = new[] {
new CGColor (1f, 1f, 1f),
new CGColor (1f, .3f, 0f)
},
+ Actions = new Foundation.NSDictionary (),
BackgroundColor = NSColor.Black.CGColor,
BorderColor = new CGColor (.5f, .5f, .5f, .5f),
BorderWidth = 1,
@@ -67,45 +68,50 @@ namespace Xamarin.PropertyEditing.Mac
{
base.LayoutSublayers ();
- Saturation.Frame = new CGRect (Margin, Margin, Frame.Width - 2 * Margin, Frame.Height - 2 * Margin);
- Brightness.Frame = Saturation.Bounds;
- Saturation.StartPoint = new CGPoint (0, .5);
- Saturation.EndPoint = new CGPoint (1, .5);
+ saturationLayer.Frame = Bounds.Inset (Margin, Margin);
+ brightnessLayer.Frame = saturationLayer.Bounds;
+ saturationLayer.StartPoint = new CGPoint (0, .5);
+ saturationLayer.EndPoint = new CGPoint (1, .5);
}
- CommonColor c;
public override void UpdateFromModel (EditorInteraction interaction)
{
LayoutIfNeeded ();
var color = interaction.Color;
- var sat = saturationEditor.LocationFromColor (Saturation, color);
- var bright = brightnessEditor.LocationFromColor (Brightness, color);
+ var sat = saturationEditor.LocationFromColor (saturationLayer, color);
+ var bright = brightnessEditor.LocationFromColor (brightnessLayer, color);
var x = sat.X;
- var y = bright.Y + Saturation.Frame.Y;
+ var y = bright.Y + saturationLayer.Frame.Y;
- Grip.Frame = new CGRect (x - GripRadius, y - GripRadius, GripRadius * 2, GripRadius * 2);
+ grip.Frame = new CGRect (x - GripRadius, y - GripRadius, GripRadius * 2, GripRadius * 2);
- if (interaction.StartColor.ToCGColor () != Saturation.Colors.Last ())
- saturationEditor.UpdateGradientLayer (Saturation, interaction.StartColor.HueColor);
+ var hueColor = interaction.Color.HueColor;
+ saturationEditor.UpdateGradientLayer (saturationLayer, hueColor);
}
public override void UpdateFromLocation (EditorInteraction interaction, CGPoint location)
{
var loc = location;
- var frame = Saturation.Frame;
+ var frame = saturationLayer.Frame;
if (interaction.ViewModel == null)
return;
var color = interaction.Color;
- var saturation = saturationEditor.ValueFromLocation (Saturation, loc);
+ var saturation = saturationEditor.ValueFromLocation (saturationLayer, loc);
var brightness = saturationEditor.ValueFromLocation (
- Brightness,
- new CGPoint (loc.X + Brightness.Frame.X, loc.Y + Brightness.Frame.Y));
+ brightnessLayer,
+ new CGPoint (loc.X + brightnessLayer.Frame.X, loc.Y + brightnessLayer.Frame.Y));
- c = interaction.Color = interaction.Color.UpdateHSB (saturation: saturation, brightness: brightness);
+ interaction.Color = interaction.Color.UpdateHSB (saturation: saturation, brightness: brightness);
+ //interaction.Shade = shade;
}
- }
+
+ public override void Commit(EditorInteraction interaction)
+ {
+ interaction.ViewModel.CommitLastColor ();
+ }
+ }
}
diff --git a/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs b/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs
index 35b3b5e..118f3e6 100644
--- a/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs
+++ b/Xamarin.PropertyEditing.Mac/Controls/Custom/SolidColorBrushEditor.cs
@@ -17,60 +17,38 @@ namespace Xamarin.PropertyEditing.Mac
public EditorInteraction (SolidBrushViewModel viewModel, ColorEditorLayer layer)
{
ViewModel = viewModel;
- StartColor = Color = viewModel.Color;
Layer = layer;
}
public ColorEditorLayer Layer { get; set; }
public SolidBrushViewModel ViewModel { get; set; }
- public CommonColor StartColor { get; }
+ public CommonColor LastColor => ViewModel.LastColor;
+ public CommonColor InitialColor => ViewModel.InitialColor;
- CommonColor color;
- public CommonColor Color
- {
- get => color;
- set {
- if (color == value)
- return;
+ public CommonColor Color {
+ get => ViewModel.Color;
+ set => ViewModel.Color = value;
+ }
- color = value;
- OnPropertyChanged ();
- }
+ public CommonColor HueColor {
+ get => ViewModel.HueColor;
+ set => ViewModel.HueColor = value;
}
- public CommonColor LastColor {
- get => ViewModel.LastColor;
+ public CommonColor Shade {
+ get => ViewModel.Shade;
+ set => ViewModel.Shade = value;
}
public void Commit ()
{
- ViewModel.Color = Color;
+ Layer.Commit (this);
}
}
class SolidColorBrushEditor : ColorEditorView
{
- readonly ShadeLayer Shade = new ShadeLayer ();
- readonly HueLayer Hue = new HueLayer ();
- readonly HistoryLayer History = new HistoryLayer ();
-
- readonly CALayer Background = new CALayer {
- CornerRadius = 3,
- BorderWidth = 1
- };
-
- readonly CALayer componentBackground = new CALayer {
- CornerRadius = 3,
- BorderWidth = 1
- };
-
- readonly ColorComponentTabViewController componentTabs = new ColorComponentTabViewController () {
- EditorType = ChannelEditorType.RGB
- };
-
- public override bool AcceptsFirstResponder() => true;
-
public SolidColorBrushEditor (IntPtr handle) : base (handle)
{
Initialize ();
@@ -95,15 +73,35 @@ namespace Xamarin.PropertyEditing.Mac
void Initialize ()
{
Layer = new CALayer ();
- Layer.AddSublayer (Background);
- Layer.AddSublayer (Shade);
- Layer.AddSublayer (Hue);
- Layer.AddSublayer (History);
+ Layer.AddSublayer (background);
+ Layer.AddSublayer (shadeLayer);
+ Layer.AddSublayer (hueLayer);
+ Layer.AddSublayer (historyLayer);
Layer.AddSublayer (componentBackground);
WantsLayer = true;
AddSubview (componentTabs.View);
}
+ readonly ColorComponentTabViewController componentTabs = new ColorComponentTabViewController () {
+ EditorType = ChannelEditorType.RGB
+ };
+
+ public override bool AcceptsFirstResponder() => true;
+
+ readonly ShadeLayer shadeLayer = new ShadeLayer ();
+ readonly HueLayer hueLayer = new HueLayer ();
+ readonly HistoryLayer historyLayer = new HistoryLayer ();
+
+ readonly CALayer background = new CALayer {
+ CornerRadius = 3,
+ BorderWidth = 1
+ };
+
+ readonly CALayer componentBackground = new CALayer {
+ CornerRadius = 3,
+ BorderWidth = 1
+ };
+
EditorInteraction interaction;
public override void UpdateFromEvent (NSEvent theEvent)
{
@@ -154,16 +152,15 @@ namespace Xamarin.PropertyEditing.Mac
interaction = null;
}
+ bool modelChanged = true;
protected override void OnPropertyChanged (object sender, PropertyChangedEventArgs e)
{
var inter = interaction ?? new EditorInteraction (ViewModel, null);
switch (e.PropertyName) {
case nameof (SolidBrushViewModel.Color):
- case nameof (SolidBrushViewModel.HueColor):
- foreach (var editor in Layer.Sublayers.OfType<ColorEditorLayer> ()) {
- editor.UpdateFromModel (inter);
- }
+ case nameof (SolidBrushViewModel.LastColor):
+ modelChanged = NeedsLayout = true;
break;
}
}
@@ -172,8 +169,9 @@ namespace Xamarin.PropertyEditing.Mac
{
base.OnViewModelChanged(oldModel);
var inter = interaction ?? new EditorInteraction (ViewModel, null);
+
componentTabs.ViewModel = ViewModel;
- foreach (var editor in Layer.Sublayers.OfType<ColorEditorLayer> ()) {
+ foreach (var editor in Layer.Sublayers.OfType<ColorEditorLayer> ()) {
editor.UpdateFromModel (inter);
}
}
@@ -182,6 +180,14 @@ namespace Xamarin.PropertyEditing.Mac
{
base.Layout ();
+ if (modelChanged) {
+ var interx = interaction ?? new EditorInteraction (ViewModel, null);
+ foreach (var editor in Layer.Sublayers.OfType<ColorEditorLayer> ()) {
+ editor.UpdateFromModel (interx);
+ }
+ modelChanged = false;
+ }
+
if (Frame.IsEmpty || Frame.IsInfinite () || double.IsNaN (Frame.X) || double.IsInfinity (Frame.X))
return;
@@ -191,23 +197,22 @@ namespace Xamarin.PropertyEditing.Mac
var secondBase = padding + secondarySpan;
var firstStop = firstBase + primarySpan;
- Background.BorderColor = new CGColor (.5f, .5f, .5f, .5f);
- Background.BackgroundColor = NSColor.ControlBackground.CGColor;
- Background.Frame = new CGRect (0, 0, Frame.Height, Frame.Height);
- //Background.SetNeedsDisplay ();
+ background.BorderColor = new CGColor (.5f, .5f, .5f, .5f);
+ background.BackgroundColor = NSColor.ControlBackground.CGColor;
+ background.Frame = new CGRect (0, 0, Frame.Height, Frame.Height);
componentBackground.BorderColor = new CGColor (.5f, .5f, .5f, .5f);
componentBackground.BackgroundColor = NSColor.ControlBackground.CGColor;
componentBackground.Frame = new CGRect (0, 0, Frame.Height, Frame.Height);
- //componentBackground.SetNeedsDisplay ();
+
var x = Frame.Height + 4 * padding;
componentBackground.Frame = new CGRect (Frame.Height + 4 * padding, 0, Frame.Width - x, Frame.Height);
- Hue.Frame = new CGRect (firstStop, secondBase, secondarySpan, primarySpan);
- Hue.GripColor = NSColor.Text.CGColor;
- //Hue.SetNeedsDisplay ();
- Shade.Frame = new CGRect (firstBase, secondBase, primarySpan, primarySpan);
- History.Frame = new CGRect (firstBase, firstBase, primarySpan, secondarySpan);
+ hueLayer.Frame = new CGRect (firstStop, secondBase, secondarySpan, primarySpan);
+ hueLayer.GripColor = NSColor.Text.CGColor;
+
+ shadeLayer.Frame = new CGRect (firstBase, secondBase, primarySpan, primarySpan);
+ historyLayer.Frame = new CGRect (firstBase, firstBase, primarySpan, secondarySpan);
var inter = interaction ?? new EditorInteraction (ViewModel, null);
foreach (var editor in Layer.Sublayers.OfType<ColorEditorLayer> ()) {
editor.UpdateFromModel (inter);