aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/TEMP
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-05-28 13:56:27 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-05-28 13:56:27 +0300
commitc6ee9ffa1bffeb9f743d914e6ef0d326c8c27d4c (patch)
tree85f10f370c92c415aee0eea28318b2a3fac47451 /Software/Visual_Studio/TEMP
parent1616df43a043c24c9f788156234c04cf5305590a (diff)
downloadTango-c6ee9ffa1bffeb9f743d914e6ef0d326c8c27d4c.tar.gz
Tango-c6ee9ffa1bffeb9f743d914e6ef0d326c8c27d4c.zip
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...
Diffstat (limited to 'Software/Visual_Studio/TEMP')
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Graphics2D/BindingEventArgs.cs4
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Graphics2D/BindingEventContainer.cs39
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DCanvas.cs5
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DContext.cs27
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DFrame.cs46
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DHost.cs68
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Graphics2D/Drawing2DStackPanel.cs20
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Graphics2D/IVisualBinder.cs4
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Graphics2D/Images/sample.pngbin0 -> 5793 bytes
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Graphics2D/MainWindow.xaml35
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Graphics2D/Tango.Graphics2D.csproj9
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinderResult.cs51
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/BorderBinder.cs55
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/EllipseBinder.cs39
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/ImageBinder.cs35
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/LineBinder.cs48
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/PathBinder.cs67
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/RectangleBinder.cs39
-rw-r--r--Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/TextBlockBinder.cs85
19 files changed, 436 insertions, 240 deletions
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<T> : 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
@@ -11,34 +11,18 @@ namespace Tango.Graphics2D
{
public class BindingEventContainer : DependencyObject
{
- public static BindingEventContainer<T> Generate<T>(DrawingVisual visual, FrameworkElement element, DependencyProperty elementProperty)
- {
- BindingEventContainer<T> container = new BindingEventContainer<T>(visual, element);
-
- Binding binding = new Binding();
- binding.Mode = BindingMode.OneWay;
- binding.Source = element;
- binding.Path = new PropertyPath(elementProperty);
- BindingOperations.SetBinding(container, BindingEventContainer<T>.ValueProperty, binding);
-
- return container;
- }
- }
-
- public class BindingEventContainer<T> : BindingEventContainer
- {
private DrawingVisual _visual;
private FrameworkElement _element;
- public event EventHandler<BindingEventArgs<T>> ValueChanged;
+ public event EventHandler<BindingEventArgs> 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<T>), new PropertyMetadata(default(T), (d, e) => (d as BindingEventContainer<T>).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<T>()
+ 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<Rectangle>(new RectangleBinder());
RegisterVisualBinder<Ellipse>(new EllipseBinder());
RegisterVisualBinder<Border>(new BorderBinder());
+ RegisterVisualBinder<Image>(new ImageBinder());
+ RegisterVisualBinder<Line>(new LineBinder());
+ RegisterVisualBinder<Path>(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<DependencyProperty> 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
--- /dev/null
+++ b/Software/Visual_Studio/TEMP/Tango.Graphics2D/Images/sample.png
Binary files 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 @@
<Ellipse Margin="20 0 0 0" MouseUp="Ellipse_MouseUp" Fill="Blue" Width="100" Height="100"></Ellipse>
</local:Drawing2DStackPanel>-->
- <Grid Width="200" Height="100" Margin="0 10 0 0">
- <local:Drawing2DFrame>
- <Border x:Name="border" MouseDown="Border_MouseDown" MouseUp="Border_MouseUp" Background="Gainsboro" BorderBrush="DimGray" BorderThickness="1" CornerRadius="5">
+ <Grid Width="300" Height="100" Margin="0 10 0 0">
+ <local:Drawing2DFrame CanResize="True">
+ <Border x:Name="border" Margin="10" MouseDown="Border_MouseDown" MouseUp="Border_MouseUp" Background="Gainsboro" BorderBrush="DimGray" BorderThickness="1" CornerRadius="5">
</Border>
- <TextBlock x:Name="txt" MouseEnter="Txt_MouseEnter" MouseLeave="Txt_MouseLeave" MouseDown="Txt_MouseDown" Text="Roy Ben Shabat" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10">
+ <Ellipse Fill="Blue" Width="50" Height="50">
+
+ </Ellipse>
+ <TextBlock x:Name="txt" MouseEnter="Txt_MouseEnter" MouseLeave="Txt_MouseLeave" MouseDown="Txt_MouseDown" Text="HGI Roy asd as" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10">
+ <TextBlock.Foreground>
+ <SolidColorBrush Color="Red" />
+ </TextBlock.Foreground>
<TextBlock.Triggers>
<EventTrigger RoutedEvent="MouseEnter">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0.5" Duration="00:00:0.3"></DoubleAnimation>
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" To="1.2" Duration="00:00:0.3"></DoubleAnimation>
+ <ColorAnimation Storyboard.TargetProperty="Foreground.Color" To="Blue" Duration="00:00:0.3"></ColorAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
@@ -63,6 +70,7 @@
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="00:00:0.3"></DoubleAnimation>
<DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleX" To="1" Duration="00:00:0.3"></DoubleAnimation>
+ <ColorAnimation Storyboard.TargetProperty="Foreground.Color" To="Red" Duration="00:00:0.3"></ColorAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
@@ -71,6 +79,25 @@
<ScaleTransform ScaleX="1" ScaleY="1" CenterX="50" CenterY="0.5" />
</TextBlock.RenderTransform>
</TextBlock>
+
+ <Line Stroke="Red" X1="0" Y1="0" X2="30" Y2="30"></Line>
+ <Image Source="/Images/sample.png" Width="50" Height="50" />
+
+ <Path Stroke="Black" StrokeThickness="5" Fill="Goldenrod" Stretch="Fill">
+ <Path.Data>
+ <PathGeometry>
+ <PathGeometry.Figures>
+ <PathFigure StartPoint="100,50" IsClosed="True">
+ <LineSegment Point="140,60"/>
+ <LineSegment Point="150,100"/>
+ <LineSegment Point="125,120"/>
+ <LineSegment Point="90,110"/>
+ <LineSegment Point="80,80"/>
+ </PathFigure>
+ </PathGeometry.Figures>
+ </PathGeometry>
+ </Path.Data>
+ </Path>
</local:Drawing2DFrame>
</Grid>
</StackPanel>
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 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
- <Compile Include="VisualBinderResult.cs" />
<Compile Include="VisualBinders\BorderBinder.cs" />
<Compile Include="VisualBinders\EllipseBinder.cs" />
+ <Compile Include="VisualBinders\ImageBinder.cs" />
+ <Compile Include="VisualBinders\LineBinder.cs" />
+ <Compile Include="VisualBinders\PathBinder.cs" />
<Compile Include="VisualBinders\RectangleBinder.cs" />
<Compile Include="VisualBinders\TextBlockBinder.cs" />
<Page Include="MainWindow.xaml">
@@ -71,7 +73,6 @@
<Compile Include="BindingEventContainer.cs" />
<Compile Include="BindingEventArgs.cs" />
<Compile Include="Drawing2DCanvas.cs" />
- <Compile Include="Drawing2DContext.cs" />
<Compile Include="Drawing2DFrame.cs" />
<Compile Include="Drawing2DHost.cs" />
<Compile Include="Drawing2DStackPanel.cs" />
@@ -108,6 +109,8 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
- <ItemGroup />
+ <ItemGroup>
+ <Resource Include="Images\sample.png" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> \ 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<BindingEventContainer> BindingEventContainers { get; set; }
-
- public VisualBinderResult(DrawingVisual visual)
- {
- Visual = visual;
- BindingEventContainers = new List<BindingEventContainer>();
- }
-
- public void AddBasicContainers(FrameworkElement element)
- {
- AddOpacityContainer(element);
- AddVisibilityContainer(element);
- }
-
- private void AddOpacityContainer(FrameworkElement element)
- {
- var container = BindingEventContainer.Generate<double>(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<Visibility>(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<Brush>(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<DependencyProperty> GetRenderProperties()
+ {
+ return new List<DependencyProperty>()
+ {
+ 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<DependencyProperty> GetRenderProperties()
+ {
+ return new List<DependencyProperty>()
+ {
+ 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<DependencyProperty> GetRenderProperties()
+ {
+ return new List<DependencyProperty>()
+ {
+ 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<DependencyProperty> GetRenderProperties()
+ {
+ return new List<DependencyProperty>()
+ {
+ 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<DependencyProperty> GetRenderProperties()
+ {
+ return new List<DependencyProperty>()
+ {
+ 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<DependencyProperty> GetRenderProperties()
+ {
+ return new List<DependencyProperty>()
+ {
+ 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<Tuple<FormattedText, double>> runs = new List<Tuple<FormattedText, double>>();
-
- foreach (var run in textBlock.Inlines.OfType<Run>())
- {
- 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<Tuple<FormattedText, double>> runs = new List<Tuple<FormattedText, double>>();
- formattedText.MaxTextWidth = host.ActualWidth;
-
- double w = formattedText.WidthIncludingTrailingWhitespace;
-
- runs.Add(new Tuple<FormattedText, double>(formattedText, w));
+ foreach (var run in textBlock.Inlines.OfType<Run>())
+ {
+ 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, double>(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<DependencyProperty> GetRenderProperties()
+ {
+ return new List<DependencyProperty>()
+ {
+ TextBlock.OpacityProperty,
+ TextBlock.VisibilityProperty,
+ TextBlock.ForegroundProperty,
+ TextBlock.TextProperty,
+ };
+ }
}
}