From c6ee9ffa1bffeb9f743d914e6ef0d326c8c27d4c Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 28 May 2019 13:56:27 +0300 Subject: Attempt to fix camera sound on SnapMatch Fixed long color names on SnapMatch. Clear email address and message when sending new email on SnapMatch. Working on Tango.Graphics2D... --- .../views/capture/CaptureFragmentVM.java | 9 ++- .../views/sendtoemail/SendToEmailFragmentVM.java | 2 + .../app/src/main/res/layout/color_result_item.xml | 3 + .../TEMP/Tango.Graphics2D/BindingEventArgs.cs | 4 +- .../TEMP/Tango.Graphics2D/BindingEventContainer.cs | 39 +++++----- .../TEMP/Tango.Graphics2D/Drawing2DCanvas.cs | 5 ++ .../TEMP/Tango.Graphics2D/Drawing2DContext.cs | 27 ------- .../TEMP/Tango.Graphics2D/Drawing2DFrame.cs | 46 +++++++++-- .../TEMP/Tango.Graphics2D/Drawing2DHost.cs | 68 +++++++++++++++-- .../TEMP/Tango.Graphics2D/Drawing2DStackPanel.cs | 20 +++++ .../TEMP/Tango.Graphics2D/IVisualBinder.cs | 4 +- .../TEMP/Tango.Graphics2D/Images/sample.png | Bin 0 -> 5793 bytes .../TEMP/Tango.Graphics2D/MainWindow.xaml | 35 ++++++++- .../TEMP/Tango.Graphics2D/Tango.Graphics2D.csproj | 9 ++- .../TEMP/Tango.Graphics2D/VisualBinderResult.cs | 51 ------------- .../Tango.Graphics2D/VisualBinders/BorderBinder.cs | 55 +++++-------- .../VisualBinders/EllipseBinder.cs | 39 +++++----- .../Tango.Graphics2D/VisualBinders/ImageBinder.cs | 35 +++++++++ .../Tango.Graphics2D/VisualBinders/LineBinder.cs | 48 ++++++++++++ .../Tango.Graphics2D/VisualBinders/PathBinder.cs | 67 ++++++++++++++++ .../VisualBinders/RectangleBinder.cs | 39 +++++----- .../VisualBinders/TextBlockBinder.cs | 85 ++++++++++----------- 22 files changed, 448 insertions(+), 242 deletions(-) delete mode 100644 Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DContext.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Graphics2D/Images/sample.png delete mode 100644 Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinderResult.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/ImageBinder.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/LineBinder.cs create mode 100644 Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/PathBinder.cs (limited to 'Software') diff --git a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/capture/CaptureFragmentVM.java b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/capture/CaptureFragmentVM.java index 5ce70e284..169f553a7 100644 --- a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/capture/CaptureFragmentVM.java +++ b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/capture/CaptureFragmentVM.java @@ -2,6 +2,8 @@ package com.twine.colorcapture.views.capture; import android.graphics.Bitmap; import android.media.MediaActionSound; +import android.os.Handler; +import android.os.Looper; import android.util.Log; import com.squareup.otto.Bus; @@ -143,8 +145,11 @@ public class CaptureFragmentVM extends ViewModelBase implement //ToneGenerator toneGen1 = new ToneGenerator(AudioManager.STREAM_MUSIC, 100); //toneGen1.startTone(ToneGenerator.TONE_CDMA_PIP, 150); - MediaActionSound sound = new MediaActionSound(); - sound.play(MediaActionSound.SHUTTER_CLICK); + new Handler(Looper.getMainLooper()).post(() -> + { + MediaActionSound sound = new MediaActionSound(); + sound.play(MediaActionSound.SHUTTER_CLICK); + }); isCardDetected.set(true); preventDetection = true; diff --git a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/sendtoemail/SendToEmailFragmentVM.java b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/sendtoemail/SendToEmailFragmentVM.java index 2a89f706e..4cb2896fa 100644 --- a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/sendtoemail/SendToEmailFragmentVM.java +++ b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/sendtoemail/SendToEmailFragmentVM.java @@ -104,6 +104,8 @@ public class SendToEmailFragmentVM extends ViewModelBase i @Override public void onNavigationObjectReceived(ColorResult colorResult) { + this.to.set(""); + this.message.set(""); this.colorResult = colorResult; } } diff --git a/Software/Android_Studio/ColorCapture/app/src/main/res/layout/color_result_item.xml b/Software/Android_Studio/ColorCapture/app/src/main/res/layout/color_result_item.xml index 139ddc5b3..cc35b0f55 100644 --- a/Software/Android_Studio/ColorCapture/app/src/main/res/layout/color_result_item.xml +++ b/Software/Android_Studio/ColorCapture/app/src/main/res/layout/color_result_item.xml @@ -63,10 +63,13 @@ android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="5dp" + android:paddingRight="100dp" android:fontFamily="@font/flexo_medium" android:letterSpacing="0.07" android:text="@{result.result.name}" android:textSize="@dimen/medium_font_size" + android:maxLines="1" + android:ellipsize="end" tools:text="Nike 100" /> diff --git a/Software/Visual_Studio/TEMP/Tango.Graphics2D/BindingEventArgs.cs b/Software/Visual_Studio/TEMP/Tango.Graphics2D/BindingEventArgs.cs index 90299fe8f..fbf3277b2 100644 --- a/Software/Visual_Studio/TEMP/Tango.Graphics2D/BindingEventArgs.cs +++ b/Software/Visual_Studio/TEMP/Tango.Graphics2D/BindingEventArgs.cs @@ -8,10 +8,10 @@ using System.Windows.Media; namespace Tango.Graphics2D { - public class BindingEventArgs : EventArgs + public class BindingEventArgs : EventArgs { public DrawingVisual Visual { get; set; } public FrameworkElement Element { get; set; } - public T Value { get; set; } + public Object Value { get; set; } } } diff --git a/Software/Visual_Studio/TEMP/Tango.Graphics2D/BindingEventContainer.cs b/Software/Visual_Studio/TEMP/Tango.Graphics2D/BindingEventContainer.cs index 6de81b02e..759b5d0bc 100644 --- a/Software/Visual_Studio/TEMP/Tango.Graphics2D/BindingEventContainer.cs +++ b/Software/Visual_Studio/TEMP/Tango.Graphics2D/BindingEventContainer.cs @@ -10,35 +10,19 @@ using System.Windows.Media; namespace Tango.Graphics2D { public class BindingEventContainer : DependencyObject - { - public static BindingEventContainer Generate(DrawingVisual visual, FrameworkElement element, DependencyProperty elementProperty) - { - BindingEventContainer container = new BindingEventContainer(visual, element); - - Binding binding = new Binding(); - binding.Mode = BindingMode.OneWay; - binding.Source = element; - binding.Path = new PropertyPath(elementProperty); - BindingOperations.SetBinding(container, BindingEventContainer.ValueProperty, binding); - - return container; - } - } - - public class BindingEventContainer : BindingEventContainer { private DrawingVisual _visual; private FrameworkElement _element; - public event EventHandler> ValueChanged; + public event EventHandler ValueChanged; - public T Value + public Object Value { - get { return (T)GetValue(ValueProperty); } + get { return (Object)GetValue(ValueProperty); } set { SetValue(ValueProperty, value); } } public static readonly DependencyProperty ValueProperty = - DependencyProperty.Register("Value", typeof(T), typeof(BindingEventContainer), new PropertyMetadata(default(T), (d, e) => (d as BindingEventContainer).OnValueChanged())); + DependencyProperty.Register("Value", typeof(Object), typeof(BindingEventContainer), new PropertyMetadata(null, (d, e) => (d as BindingEventContainer).OnValueChanged())); public BindingEventContainer(DrawingVisual visual, FrameworkElement element) { @@ -48,12 +32,25 @@ namespace Tango.Graphics2D private void OnValueChanged() { - ValueChanged?.Invoke(this, new BindingEventArgs() + ValueChanged?.Invoke(this, new BindingEventArgs() { Element = _element, Visual = _visual, Value = Value, }); } + + public static BindingEventContainer Generate(DrawingVisual visual, FrameworkElement element, DependencyProperty elementProperty) + { + BindingEventContainer container = new BindingEventContainer(visual, element); + + Binding binding = new Binding(); + binding.Mode = BindingMode.OneWay; + binding.Source = element; + binding.Path = new PropertyPath(elementProperty); + BindingOperations.SetBinding(container, BindingEventContainer.ValueProperty, binding); + + return container; + } } } diff --git a/Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DCanvas.cs b/Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DCanvas.cs index 4625615f6..38b3b2acb 100644 --- a/Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DCanvas.cs +++ b/Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DCanvas.cs @@ -32,5 +32,10 @@ namespace Tango.Graphics2D return location; } + + public override Size GetElementSize(FrameworkElement element) + { + return new Size(element.Width, element.Height); + } } } diff --git a/Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DContext.cs b/Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DContext.cs deleted file mode 100644 index fead16dba..000000000 --- a/Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DContext.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Media; - -namespace Tango.Graphics2D -{ - public class Drawing2DContext : IDisposable - { - public DrawingVisual Visual { get; private set; } - - public DrawingContext Context { get; private set; } - - public Drawing2DContext() - { - Visual = new DrawingVisual(); - Context = Visual.RenderOpen(); - } - - public void Dispose() - { - Context.Close(); - } - } -} diff --git a/Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DFrame.cs b/Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DFrame.cs index eec52829b..7339c900d 100644 --- a/Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DFrame.cs +++ b/Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DFrame.cs @@ -19,43 +19,73 @@ namespace Tango.Graphics2D } else if (element.VerticalAlignment == VerticalAlignment.Bottom) { - return new Point(element.Margin.Left, ActualHeight - element.Height - element.Margin.Bottom); + return new Point(element.Margin.Left, ActualHeight - GetElementHeight(element) - element.Margin.Bottom); } else { - return new Point(element.Margin.Left, (ActualHeight / 2) - (element.Height / 2) + element.Margin.Top - element.Margin.Bottom); + return new Point(element.Margin.Left, (ActualHeight / 2) - (GetElementHeight(element) / 2) + element.Margin.Top - element.Margin.Bottom); } } else if (element.HorizontalAlignment == HorizontalAlignment.Right) { if (element.VerticalAlignment == VerticalAlignment.Top) { - return new Point(ActualWidth - element.Width - element.Margin.Right, element.Margin.Top); + return new Point(ActualWidth - GetElementWidth(element) - element.Margin.Right, element.Margin.Top); } else if (element.VerticalAlignment == VerticalAlignment.Bottom) { - return new Point(ActualWidth - element.Width - element.Margin.Right, ActualHeight - element.Height - element.Margin.Bottom); + return new Point(ActualWidth - GetElementWidth(element) - element.Margin.Right, ActualHeight - GetElementHeight(element) - element.Margin.Bottom); } else { - return new Point(ActualWidth - element.Width - element.Margin.Right, (ActualHeight / 2) - (element.Height / 2) + element.Margin.Top - element.Margin.Bottom); + return new Point(ActualWidth - GetElementWidth(element) - element.Margin.Right, (ActualHeight / 2) - (GetElementHeight(element) / 2) + element.Margin.Top - element.Margin.Bottom); } } else { if (element.VerticalAlignment == VerticalAlignment.Top) { - return new Point((ActualWidth / 2) - (element.Width / 2) + element.Margin.Left - element.Margin.Right, element.Margin.Top); + return new Point((ActualWidth / 2) - (GetElementWidth(element) / 2) + element.Margin.Left - element.Margin.Right, element.Margin.Top); } else if (element.VerticalAlignment == VerticalAlignment.Bottom) { - return new Point((ActualWidth / 2) - (element.Width / 2) + element.Margin.Left - element.Margin.Right, ActualHeight - element.Height - element.Margin.Bottom); + return new Point((ActualWidth / 2) - (GetElementWidth(element) / 2) + element.Margin.Left - element.Margin.Right, ActualHeight - GetElementHeight(element) - element.Margin.Bottom); } else { - return new Point((ActualWidth / 2) - (element.Width / 2) + element.Margin.Left - element.Margin.Right, (ActualHeight / 2) - (element.Height / 2) + element.Margin.Top - element.Margin.Bottom); + return new Point((ActualWidth / 2) - (GetElementWidth(element) / 2) + element.Margin.Left, (ActualHeight / 2) - (GetElementHeight(element) / 2) + element.Margin.Top); } } } + + private double GetElementWidth(FrameworkElement element) + { + return double.IsNaN(element.Width) ? ActualWidth : element.Width; + } + + private double GetElementHeight(FrameworkElement element) + { + return double.IsNaN(element.Height) ? ActualHeight : element.Height; + } + + public override Size GetElementSize(FrameworkElement element) + { + double width = element.Width; + double height = element.Height; + + if (double.IsNaN(width)) + { + width = ActualWidth; + } + if (double.IsNaN(height)) + { + height = ActualHeight; + } + + width -= (element.Margin.Left + element.Margin.Right); + height -= (element.Margin.Top + element.Margin.Bottom); + + return new Size(width, height); + } } } diff --git a/Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DHost.cs b/Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DHost.cs index 7d03689dc..9574b4082 100644 --- a/Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DHost.cs +++ b/Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DHost.cs @@ -42,6 +42,15 @@ namespace Tango.Graphics2D public static readonly DependencyProperty ForegroundProperty = TextBlock.ForegroundProperty.AddOwner(typeof(Drawing2DHost)); + public bool CanResize + { + get { return (bool)GetValue(CanResizeProperty); } + set { SetValue(CanResizeProperty, value); } + } + public static readonly DependencyProperty CanResizeProperty = + DependencyProperty.Register("CanResize", typeof(bool), typeof(Drawing2DHost), new PropertyMetadata(false)); + + #endregion #region Constructors @@ -58,13 +67,17 @@ namespace Tango.Graphics2D RegisterVisualBinder(new RectangleBinder()); RegisterVisualBinder(new EllipseBinder()); RegisterVisualBinder(new BorderBinder()); + RegisterVisualBinder(new ImageBinder()); + RegisterVisualBinder(new LineBinder()); + RegisterVisualBinder(new PathBinder()); Loaded += Drawing2DHost_Loaded; + SizeChanged += Drawing2DHost_SizeChanged; } #endregion - #region Loaded Event + #region Host Events private void Drawing2DHost_Loaded(object sender, RoutedEventArgs e) { @@ -82,6 +95,14 @@ namespace Tango.Graphics2D } } + private void Drawing2DHost_SizeChanged(object sender, SizeChangedEventArgs e) + { + foreach (var item in _elements) + { + InvalidateElement(item.Key, item.Value); + } + } + #endregion #region Mouse Interactions @@ -248,15 +269,47 @@ namespace Tango.Graphics2D private void DrawElement(FrameworkElement element) { - IVisualBinder binder = _binders[element.GetType()]; + DrawingVisual visual = new DrawingVisual(); - var result = binder.CreateVisual(element, this); + IVisualBinder binder = InvalidateElement(visual, element); - _containers.AddRange(result.BindingEventContainers); + AddVisual(visual, element); - DrawingVisual visual = result.Visual; + foreach (var dp in binder.GetRenderProperties()) + { + var container = BindingEventContainer.Generate(visual, element, dp); + container.ValueChanged += (sender, e) => + { + InvalidateElement(e.Visual, e.Element); + }; - AddVisual(visual, element); + _containers.Add(container); + } + } + + private IVisualBinder InvalidateElement(DrawingVisual visual, FrameworkElement element) + { + var context = visual.RenderOpen(); + + IVisualBinder binder = null; + + if (!_binders.TryGetValue(element.GetType(), out binder)) + { + throw new InvalidOperationException($"No visual binder is registered for element type '{element.GetType()}'"); + } + + binder.DrawVisual(element, this, context); + + visual.Opacity = element.Opacity; + + if (element.Visibility != Visibility.Visible) + { + visual.Opacity = 0; + } + + context.Close(); + + return binder; } private void AddVisual(DrawingVisual visual, FrameworkElement element) @@ -279,6 +332,8 @@ namespace Tango.Graphics2D public abstract Point GetElementLocation(FrameworkElement element); + public abstract Size GetElementSize(FrameworkElement element); + #endregion #region Binders @@ -314,5 +369,6 @@ namespace Tango.Graphics2D } #endregion + } } diff --git a/Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DStackPanel.cs b/Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DStackPanel.cs index edcaa34f6..e27e0435f 100644 --- a/Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DStackPanel.cs +++ b/Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DStackPanel.cs @@ -86,5 +86,25 @@ namespace Tango.Graphics2D return new Size(_currentPosition, _maxPosition); } } + + public override Size GetElementSize(FrameworkElement element) + { + double width = element.Width; + double height = element.Height; + + if (double.IsNaN(width)) + { + width = ActualWidth; + } + if (double.IsNaN(height)) + { + height = ActualHeight; + } + + width -= (element.Margin.Left + element.Margin.Right); + height -= (element.Margin.Top + element.Margin.Bottom); + + return new Size(width, height); + } } } diff --git a/Software/Visual_Studio/TEMP/Tango.Graphics2D/IVisualBinder.cs b/Software/Visual_Studio/TEMP/Tango.Graphics2D/IVisualBinder.cs index 07ce9e338..1b624442b 100644 --- a/Software/Visual_Studio/TEMP/Tango.Graphics2D/IVisualBinder.cs +++ b/Software/Visual_Studio/TEMP/Tango.Graphics2D/IVisualBinder.cs @@ -10,6 +10,8 @@ namespace Tango.Graphics2D { public interface IVisualBinder { - VisualBinderResult CreateVisual(FrameworkElement element, Drawing2DHost host); + void DrawVisual(FrameworkElement element, Drawing2DHost host, DrawingContext context); + + List GetRenderProperties(); } } diff --git a/Software/Visual_Studio/TEMP/Tango.Graphics2D/Images/sample.png b/Software/Visual_Studio/TEMP/Tango.Graphics2D/Images/sample.png new file mode 100644 index 000000000..b2e6c4f9f Binary files /dev/null and b/Software/Visual_Studio/TEMP/Tango.Graphics2D/Images/sample.png differ diff --git a/Software/Visual_Studio/TEMP/Tango.Graphics2D/MainWindow.xaml b/Software/Visual_Studio/TEMP/Tango.Graphics2D/MainWindow.xaml index 1c69bbfed..8a2dd2fc2 100644 --- a/Software/Visual_Studio/TEMP/Tango.Graphics2D/MainWindow.xaml +++ b/Software/Visual_Studio/TEMP/Tango.Graphics2D/MainWindow.xaml @@ -43,18 +43,25 @@ --> - - - + + + - + + + + + + + + @@ -63,6 +70,7 @@ + @@ -71,6 +79,25 @@ + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/TEMP/Tango.Graphics2D/Tango.Graphics2D.csproj b/Software/Visual_Studio/TEMP/Tango.Graphics2D/Tango.Graphics2D.csproj index 1bbee5a09..c6600ea80 100644 --- a/Software/Visual_Studio/TEMP/Tango.Graphics2D/Tango.Graphics2D.csproj +++ b/Software/Visual_Studio/TEMP/Tango.Graphics2D/Tango.Graphics2D.csproj @@ -55,9 +55,11 @@ MSBuild:Compile Designer - + + + @@ -71,7 +73,6 @@ - @@ -108,6 +109,8 @@ - + + + \ No newline at end of file diff --git a/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinderResult.cs b/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinderResult.cs deleted file mode 100644 index 28adab506..000000000 --- a/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinderResult.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Media; - -namespace Tango.Graphics2D -{ - public class VisualBinderResult - { - public DrawingVisual Visual { get; set; } - - public List BindingEventContainers { get; set; } - - public VisualBinderResult(DrawingVisual visual) - { - Visual = visual; - BindingEventContainers = new List(); - } - - public void AddBasicContainers(FrameworkElement element) - { - AddOpacityContainer(element); - AddVisibilityContainer(element); - } - - private void AddOpacityContainer(FrameworkElement element) - { - var container = BindingEventContainer.Generate(Visual, element, FrameworkElement.OpacityProperty); - container.ValueChanged += (sender, e) => - { - e.Visual.Opacity = e.Value; - }; - - BindingEventContainers.Add(container); - } - - private void AddVisibilityContainer(FrameworkElement element) - { - var container = BindingEventContainer.Generate(Visual, element, FrameworkElement.VisibilityProperty); - container.ValueChanged += (sender, e) => - { - e.Visual.Opacity = e.Value == Visibility.Visible ? 1 : 0; - }; - - BindingEventContainers.Add(container); - } - } -} diff --git a/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/BorderBinder.cs b/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/BorderBinder.cs index 622e12b41..05f24c763 100644 --- a/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/BorderBinder.cs +++ b/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/BorderBinder.cs @@ -11,49 +11,32 @@ namespace Tango.Graphics2D.VisualBinders { public class BorderBinder : IVisualBinder { - public VisualBinderResult CreateVisual(FrameworkElement element, Drawing2DHost host) + public void DrawVisual(FrameworkElement element, Drawing2DHost host, DrawingContext context) { Border border = element as Border; - using (Drawing2DContext d2 = new Drawing2DContext()) - { - if (double.IsNaN(border.Width)) - { - border.Width = host.ActualWidth; - } - if (double.IsNaN(border.Height)) - { - border.Height = host.ActualHeight; - } - - var x = d2.Context; - - var location = host.GetElementLocation(border); + var location = host.GetElementLocation(border); + var size = host.GetElementSize(border); - Pen pen = null; + Pen pen = null; - if (border.BorderBrush != null) - { - pen = new Pen(border.BorderBrush, border.BorderThickness.Top); - } - - x.DrawRoundedRectangle(border.Background, pen, new Rect(location.X, location.Y, border.Width, border.Height), border.CornerRadius.TopLeft, border.CornerRadius.BottomRight); - - VisualBinderResult result = new VisualBinderResult(d2.Visual); - result.AddBasicContainers(element); + if (border.BorderBrush != null) + { + pen = new Pen(border.BorderBrush, border.BorderThickness.Top); + } - //Background Binding - var backgroundContainer = BindingEventContainer.Generate(result.Visual, element, Border.BackgroundProperty); - backgroundContainer.ValueChanged += (sender, e) => - { - var context = e.Visual.RenderOpen(); - context.DrawRoundedRectangle(border.Background, pen, new Rect(location.X, location.Y, border.Width, border.Height), border.CornerRadius.TopLeft, border.CornerRadius.BottomRight); - context.Close(); - }; - result.BindingEventContainers.Add(backgroundContainer); + context.DrawRoundedRectangle(border.Background, pen, new Rect(location.X, location.Y, size.Width, size.Height), border.CornerRadius.TopLeft, border.CornerRadius.BottomRight); + } - return result; - } + public List GetRenderProperties() + { + return new List() + { + Border.OpacityProperty, + Border.VisibilityProperty, + Border.BackgroundProperty, + Border.MarginProperty, + }; } } } diff --git a/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/EllipseBinder.cs b/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/EllipseBinder.cs index 0b67e272c..53bfde59a 100644 --- a/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/EllipseBinder.cs +++ b/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/EllipseBinder.cs @@ -11,32 +11,33 @@ namespace Tango.Graphics2D.VisualBinders { public class EllipseBinder : IVisualBinder { - public VisualBinderResult CreateVisual(FrameworkElement element, Drawing2DHost host) + public void DrawVisual(FrameworkElement element, Drawing2DHost host, DrawingContext context) { Ellipse ellipse = element as Ellipse; - using (Drawing2DContext d2 = new Drawing2DContext()) - { - var x = d2.Context; - - var location = host.GetElementLocation(ellipse); - - Pen pen = null; + var location = host.GetElementLocation(ellipse); + var size = host.GetElementSize(ellipse); - if (ellipse.Stroke != null) - { - pen = new Pen(ellipse.Stroke, ellipse.StrokeThickness); - pen.DashCap = ellipse.StrokeDashCap; - //TODO: add some stroke features... - } + Pen pen = null; - x.DrawEllipse(ellipse.Fill, pen, new Point(location.X + ellipse.Width / 2, location.Y + ellipse.Height / 2), ellipse.Width / 2, ellipse.Height / 2); + if (ellipse.Stroke != null) + { + pen = new Pen(ellipse.Stroke, ellipse.StrokeThickness); + pen.DashCap = ellipse.StrokeDashCap; + //TODO: add some stroke features... + } - VisualBinderResult result = new VisualBinderResult(d2.Visual); - result.AddBasicContainers(element); + context.DrawEllipse(ellipse.Fill, pen, new Point(location.X + size.Width / 2, location.Y + size.Height / 2), size.Width / 2, size.Height / 2); + } - return result; - } + public List GetRenderProperties() + { + return new List() + { + Ellipse.OpacityProperty, + Ellipse.VisibilityProperty, + Ellipse.FillProperty, + }; } } } diff --git a/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/ImageBinder.cs b/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/ImageBinder.cs new file mode 100644 index 000000000..ef7603427 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/ImageBinder.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; + +namespace Tango.Graphics2D.VisualBinders +{ + public class ImageBinder : IVisualBinder + { + public void DrawVisual(FrameworkElement element, Drawing2DHost host, DrawingContext context) + { + Image image = element as Image; + + var location = host.GetElementLocation(image); + var size = host.GetElementSize(image); + + context.DrawImage(image.Source, new Rect(location.X, location.Y, size.Width, size.Height)); + } + + public List GetRenderProperties() + { + return new List() + { + Image.OpacityProperty, + Image.VisibilityProperty, + Image.SourceProperty, + Image.MarginProperty, + }; + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/LineBinder.cs b/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/LineBinder.cs new file mode 100644 index 000000000..6c6a6f0b8 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/LineBinder.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media; +using System.Windows.Shapes; + +namespace Tango.Graphics2D.VisualBinders +{ + public class LineBinder : IVisualBinder + { + public void DrawVisual(FrameworkElement element, Drawing2DHost host, DrawingContext context) + { + Line line = element as Line; + + var location = host.GetElementLocation(line); + var size = host.GetElementSize(line); + + Pen pen = null; + + if (line.Stroke != null) + { + pen = new Pen(line.Stroke, line.StrokeThickness); + pen.DashCap = line.StrokeDashCap; + //TODO: add some stroke features... + } + + context.DrawLine(pen, new Point(line.X1, line.Y1), new Point(line.X2, line.Y2)); + } + + public List GetRenderProperties() + { + return new List() + { + Line.OpacityProperty, + Line.VisibilityProperty, + Line.StrokeProperty, + Line.X1Property, + Line.Y1Property, + Line.X2Property, + Line.Y2Property, + Line.StrokeThicknessProperty + }; + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/PathBinder.cs b/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/PathBinder.cs new file mode 100644 index 000000000..903d62010 --- /dev/null +++ b/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/PathBinder.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media; +using System.Windows.Shapes; + +namespace Tango.Graphics2D.VisualBinders +{ + public class PathBinder : IVisualBinder + { + public void DrawVisual(FrameworkElement element, Drawing2DHost host, DrawingContext context) + { + Path path = element as Path; + + var location = host.GetElementLocation(path); + var size = host.GetElementSize(path); + + Pen pen = null; + + if (path.Stroke != null) + { + pen = new Pen(path.Stroke, path.StrokeThickness); + pen.DashCap = path.StrokeDashCap; + //TODO: add some stroke features... + } + + var geo = path.Data.Clone(); + + + if (path.Stretch == Stretch.Fill) + { + TransformGroup group = new TransformGroup(); + + TranslateTransform translateTransform = new TranslateTransform(); + translateTransform.X = -geo.Bounds.Left; + translateTransform.Y = -geo.Bounds.Top; + + ScaleTransform scaleTransform = new ScaleTransform(); + scaleTransform.ScaleX = size.Width / geo.Bounds.Width; + scaleTransform.ScaleY = size.Height / geo.Bounds.Height; + + group.Children.Add(translateTransform); + group.Children.Add(scaleTransform); + + context.PushTransform(group); + } + + context.DrawGeometry(path.Fill, pen, geo); + } + + public List GetRenderProperties() + { + return new List() + { + Path.OpacityProperty, + Path.VisibilityProperty, + Path.FillProperty, + Path.StrokeProperty, + Path.StrokeThicknessProperty, + Path.StretchProperty + }; + } + } +} diff --git a/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/RectangleBinder.cs b/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/RectangleBinder.cs index b77f57679..fefd6a12c 100644 --- a/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/RectangleBinder.cs +++ b/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/RectangleBinder.cs @@ -11,32 +11,33 @@ namespace Tango.Graphics2D.VisualBinders { public class RectangleBinder : IVisualBinder { - public VisualBinderResult CreateVisual(FrameworkElement element, Drawing2DHost host) + public void DrawVisual(FrameworkElement element, Drawing2DHost host, DrawingContext context) { Rectangle rectangle = element as Rectangle; - using (Drawing2DContext d2 = new Drawing2DContext()) - { - var x = d2.Context; - - var location = host.GetElementLocation(rectangle); - - Pen pen = null; + var location = host.GetElementLocation(rectangle); + var size = host.GetElementSize(rectangle); - if (rectangle.Stroke != null) - { - pen = new Pen(rectangle.Stroke, rectangle.StrokeThickness); - pen.DashCap = rectangle.StrokeDashCap; - //TODO: add some stroke features... - } + Pen pen = null; - x.DrawRectangle(rectangle.Fill, pen, new Rect(location.X, location.Y, rectangle.Width, rectangle.Height)); + if (rectangle.Stroke != null) + { + pen = new Pen(rectangle.Stroke, rectangle.StrokeThickness); + pen.DashCap = rectangle.StrokeDashCap; + //TODO: add some stroke features... + } - VisualBinderResult result = new VisualBinderResult(d2.Visual); - result.AddBasicContainers(element); + context.DrawRectangle(rectangle.Fill, pen, new Rect(location.X, location.Y, size.Width, size.Height)); + } - return result; - } + public List GetRenderProperties() + { + return new List() + { + Rectangle.OpacityProperty, + Rectangle.VisibilityProperty, + Rectangle.FillProperty, + }; } } } diff --git a/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/TextBlockBinder.cs b/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/TextBlockBinder.cs index 6e643e431..93c6574e1 100644 --- a/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/TextBlockBinder.cs +++ b/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/TextBlockBinder.cs @@ -13,64 +13,63 @@ namespace Tango.Graphics2D.VisualBinders { public class TextBlockBinder : IVisualBinder { - public VisualBinderResult CreateVisual(FrameworkElement element, Drawing2DHost host) + public void DrawVisual(FrameworkElement element, Drawing2DHost host, DrawingContext context) { TextBlock textBlock = element as TextBlock; - using (Drawing2DContext d2 = new Drawing2DContext()) - { - var x = d2.Context; - - double width = 0; - double height = 0; - - List> runs = new List>(); - - foreach (var run in textBlock.Inlines.OfType()) - { - var typeface = new Typeface( - run.FontFamily, - run.FontStyle, - run.FontWeight, - run.FontStretch); + double width = 0; + double height = 0; - var formattedText = new FormattedText(run.Text, - CultureInfo.GetCultureInfo("en-us"), - run.FlowDirection, - typeface, - run.FontSize, - run.Foreground); + List> runs = new List>(); - formattedText.MaxTextWidth = host.ActualWidth; - - double w = formattedText.WidthIncludingTrailingWhitespace; - - runs.Add(new Tuple(formattedText, w)); + foreach (var run in textBlock.Inlines.OfType()) + { + var typeface = new Typeface( + run.FontFamily, + run.FontStyle, + run.FontWeight, + run.FontStretch); - width += w; - height = Math.Max(formattedText.Height, height); - } + var formattedText = new FormattedText(run.Text, + CultureInfo.GetCultureInfo("en-us"), + run.FlowDirection, + typeface, + run.FontSize, + run.Foreground); - textBlock.Width = width; - textBlock.Height = height; + formattedText.MaxTextWidth = host.ActualWidth; - var location = host.GetElementLocation(textBlock); + double w = formattedText.WidthIncludingTrailingWhitespace; - double position_x = location.X; + runs.Add(new Tuple(formattedText, w)); - foreach (var run in runs) - { - x.DrawText(run.Item1, new Point(position_x, location.Y)); - position_x += run.Item2; - } + width += w; + height = Math.Max(formattedText.Height, height); + } - VisualBinderResult result = new VisualBinderResult(d2.Visual); - result.AddBasicContainers(element); + textBlock.Width = width; + textBlock.Height = height; + var location = host.GetElementLocation(textBlock); + double position_x = location.X; - return result; + foreach (var run in runs) + { + context.DrawText(run.Item1, new Point(position_x, location.Y)); + position_x += run.Item2; } } + + public List GetRenderProperties() + { + return new List() + { + TextBlock.OpacityProperty, + TextBlock.VisibilityProperty, + TextBlock.ForegroundProperty, + TextBlock.TextProperty, + }; + } } } -- cgit v1.3.1