Browse Source

Added functionality to display an overlay

Martin Edlund 5 years ago
parent
commit
7c008b4a09

+ 2 - 0
SketchAssistant/SketchAssistantWPF/MVP_Model.cs

@@ -310,6 +310,8 @@ namespace SketchAssistantWPF
         public void SetCurrentCursorPosition(Point p)
         {
             currentCursorPosition = p;
+            //Temporary position of the optipoint change, change this when merging with optitrack branch
+            programPresenter.MoveOptiPoint(currentCursorPosition);
             mouseDown = programPresenter.IsMousePressed();
         }
 

+ 51 - 2
SketchAssistant/SketchAssistantWPF/MVP_Presenter.cs

@@ -301,7 +301,6 @@ namespace SketchAssistantWPF
             }
         }
 
-        /*
         /// <summary>
         /// Updates the currentline
         /// </summary>
@@ -313,7 +312,7 @@ namespace SketchAssistantWPF
             currentLine.Points = new PointCollection(linepoints);
             programView.DisplayCurrLine(currentLine);
         }
-        */
+
         /// <summary>
         /// A function to update the displayed lines in the left canvas.
         /// </summary>
@@ -418,10 +417,60 @@ namespace SketchAssistantWPF
             }
         }
 
+        /// <summary>
+        /// Change the properties of an overlay item.
+        /// </summary>
+        /// <param name="name">The name of the item in the overlay dictionary</param>
+        /// <param name="visible">If the element should be visible</param>
+        /// <param name="position">The new position of the element</param>
+        public void SetOverlayStatus(String name, bool visible, Point position)
+        {
+            Shape shape = new Ellipse(); double visibility = 1; double xDif = 0; double yDif = 0;
+            switch (name)
+            {
+                case "optipoint":
+                    shape = ((MainWindow)programView).OverlayDictionary["optipoint"];
+                    visibility = 0.5; xDif = 2.5; yDif = 2.5;
+                    break;
+                case "startpoint":
+                    shape = ((MainWindow)programView).OverlayDictionary["startpoint"];
+                    xDif = ((MainWindow)programView).markerRadius; yDif = xDif;
+                    break;
+            }
+            if (visible) shape.Opacity = visibility;
+            else shape.Opacity = 0.00001;
+            Point point = ConvertRightCanvasCoordinateToOverlay(position);
+            shape.Margin = new Thickness(point.X - xDif, point.Y - yDif, 0, 0);
+        }
+
+        /// <summary>
+        /// Move the optitrack pointer to a new position.
+        /// </summary>
+        /// <param name="position">Position relative to the Rightcanvas</param>
+        public void MoveOptiPoint(Point position)
+        {
+            Point point = ConvertRightCanvasCoordinateToOverlay(position);
+            Shape shape = ((MainWindow)programView).OverlayDictionary["optipoint"];
+            shape.Margin = new Thickness(point.X - 2.5, point.Y - 2.5, 0, 0);
+        }
+
         /*************************/
         /*** HELPING FUNCTIONS ***/
         /*************************/
 
+        /// <summary>
+        /// Convert point relative to the right canvas to a point relative to the overlay canvas.
+        /// </summary>
+        /// <param name="p">The point to convert.</param>
+        /// <returns>The respective overlay canvas.</returns>
+        private Point ConvertRightCanvasCoordinateToOverlay(Point p)
+        {
+            MainWindow main = (MainWindow)programView;
+            double xDif = (main.CanvasLeftEdge.ActualWidth + main.LeftCanvas.ActualWidth + main.CanvasSeperator.ActualWidth);
+            double yDif = (main.ButtonToolbar.ActualHeight);
+            return new Point(p.X + xDif,p.Y + yDif);
+        }
+
         /// <summary>
         /// Sets the visibility of a polyline.
         /// </summary>

+ 5 - 4
SketchAssistant/SketchAssistantWPF/MainWindow.xaml

@@ -6,7 +6,7 @@
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         mc:Ignorable="d"
         Title="Sketch Assistant" Height="612" Width="914" SizeChanged="Window_SizeChanged">
-    <Grid>
+    <Grid x:Name="RootGrid">
         <Grid.ColumnDefinitions>
             <ColumnDefinition Width="5"/>
             <ColumnDefinition Width="*"/>
@@ -19,7 +19,7 @@
             <RowDefinition Height="*"/>
             <RowDefinition Height="auto"/>
         </Grid.RowDefinitions>
-        <StackPanel Orientation="Horizontal" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" Background="LightGray">
+        <StackPanel x:Name="MenuToolbar" Orientation="Horizontal" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" Background="LightGray">
             <Menu Background="LightGray"   VerticalAlignment="Center" Padding="5,0,0,0">
                 <MenuItem x:Name="LoadMenuButton" Header="Load">
                     <MenuItem x:Name="SVGMenuButton" Header="Import SVG File" Click="SVGMenuItem_Click"/>
@@ -37,7 +37,7 @@
                 </MenuItem>
             </Menu>
         </StackPanel>
-        <StackPanel Orientation="Horizontal" Grid.Column="2" Grid.Row="0" Grid.ColumnSpan="3" Background="LightGray">
+        <StackPanel x:Name="ButtonToolbar" Orientation="Horizontal" Grid.Column="2" Grid.Row="0" Grid.ColumnSpan="3" Background="LightGray">
             <Canvas Name="ToolbarSpacer" Width="5" Background="LightGray" />
             <!-- All Icons in the StackPanel taken from openclipart.org -->
             <Button x:Name="CanvasButton" ToolTip="Create a new Canvas" Click="CanvasButton_Click" BorderThickness="0">
@@ -179,7 +179,6 @@
         <InkCanvas x:Name="RightCanvas" Background="SlateGray" Grid.Column="3" Grid.Row="1" Height="auto"
             PreviewMouseDown="RightCanvas_MouseDown" MouseUp="RightCanvas_MouseUp" MouseMove="RightCanvas_MouseMove" Grid.ColumnSpan="2" 
                     StrokeCollected="RightCanvas_StrokeCollection" EditingMode="None" IsStylusCapturedChanged="RightCanvas_IsStylusCapturedChanged"/>
-
         <Canvas Name="CanvasRightEdge" Grid.Column="4" Grid.Row="1" Background="LightGray" />
 
         <DockPanel Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="8">
@@ -191,5 +190,7 @@
                 <TextBox Name="LineSimilarityBox" Text="-" Background="LightGray"/>
             </StatusBar>
         </DockPanel>
+        <Ellipse x:Name="optipoint" Opacity="0.00001" Height="5" Width="5" Fill="Black"/>
+        <Canvas x:Name="OverlayCanvas" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="5" Grid.RowSpan="3"/>
     </Grid>
 </Window>

+ 29 - 2
SketchAssistant/SketchAssistantWPF/MainWindow.xaml.cs

@@ -19,6 +19,7 @@ using System.Windows.Navigation;
 using System.Windows.Shapes;
 using System.Windows.Threading;
 using System.Windows.Ink;
+using System.Windows.Media.Effects;
 
 namespace SketchAssistantWPF
 {
@@ -50,6 +51,8 @@ namespace SketchAssistantWPF
             dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 10);
             ProgramPresenter.Resize(new Tuple<int, int>((int)LeftCanvas.Width, (int)LeftCanvas.Height),
                 new Tuple<int, int>((int)RightCanvas.Width, (int)RightCanvas.Height));
+            //Setup overlay items
+            SetupOverlay();
         }
 
         public enum ButtonState
@@ -95,7 +98,11 @@ namespace SketchAssistantWPF
         /// <summary>
         /// Size of areas marking endpoints of lines in the redraw mode.
         /// </summary>
-        int markerRadius = 10;
+        public int markerRadius = 5;
+        /// <summary>
+        /// Dictionary containing the overlay elements
+        /// </summary>
+        public Dictionary<String, Shape> OverlayDictionary = new Dictionary<string, Shape>();
 
         /********************************************/
         /*** WINDOW SPECIFIC FUNCTIONS START HERE ***/
@@ -531,7 +538,27 @@ namespace SketchAssistantWPF
         /*** HELPING FUNCTION ***/
         /************************/
 
-
+        /// <summary>
+        /// A function that generates the overlay elements and sets all their values.
+        /// </summary>
+        private void SetupOverlay()
+        {
+            DropShadowEffect effect = new DropShadowEffect(); effect.ShadowDepth = 0;
+            //Startpoint of a line to be redrawn
+            OverlayCanvas.Background = null;
+            Ellipse StartPointOverlay = new Ellipse();
+            StartPointOverlay.Height = markerRadius * 2; StartPointOverlay.Width = markerRadius * 2;
+            StartPointOverlay.Opacity = 0.00001; StartPointOverlay.Fill = Brushes.Green; StartPointOverlay.IsHitTestVisible = false;
+            OverlayDictionary.Add("startpoint", StartPointOverlay); OverlayCanvas.Children.Add(StartPointOverlay);
+            StartPointOverlay.Effect = effect;
+            //Pointer of the optitrack system
+            Ellipse OptitrackMarker = new Ellipse(); OptitrackMarker.Height = 5; OptitrackMarker.Width = 5;
+            OptitrackMarker.Opacity = 0.00001; OptitrackMarker.Fill = Brushes.Black; OptitrackMarker.IsHitTestVisible = false;
+            OverlayDictionary.Add("optipoint", OptitrackMarker); OverlayCanvas.Children.Add(OptitrackMarker);
+            OptitrackMarker.Effect = effect;
+            //Enable optipoint initially
+            ProgramPresenter.SetOverlayStatus("optipoint", true, GetCursorPosition());
+        }
 
         /// <summary>
         /// Sends inputs to the presenter simulating drawing, used for testing and debugging.