Skip to content

Commit b993c94

Browse files
committed
Support zoom in/out using mouse wheel.
1 parent 0bffb54 commit b993c94

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

Visual_Studio_2015/GraphicalDebugging/GeometryWatchControl.xaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
<RowDefinition Height="Auto" />
1616
<RowDefinition Height="0.5*" />
1717
</Grid.RowDefinitions>
18-
<Grid x:Name="imageGrid" Background="Transparent" Cursor="Cross" MouseDown="imageGrid_MouseDown" MouseMove="imageGrid_MouseMove" MouseUp="imageGrid_MouseUp" MouseLeave="imageGrid_MouseLeave" >
18+
<Grid x:Name="imageGrid" Background="Transparent" Cursor="Cross"
19+
MouseDown="imageGrid_MouseDown"
20+
MouseMove="imageGrid_MouseMove"
21+
MouseUp="imageGrid_MouseUp"
22+
MouseLeave="imageGrid_MouseLeave"
23+
MouseWheel="imageGrid_MouseWheel" >
1924
<Image x:Name="image" Stretch="Fill" Height="Auto" Width="Auto" />
2025
<Canvas x:Name="imageCanvas" Height="Auto" Width="Auto" />
2126
</Grid>

Visual_Studio_2015/GraphicalDebugging/GeometryWatchControl.xaml.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,5 +511,27 @@ private void imageGrid_MouseLeave(object sender, System.Windows.Input.MouseEvent
511511
m_mouseHLine.Visibility = Visibility.Hidden;
512512
m_mouseTxt.Visibility = Visibility.Hidden;
513513
}
514+
515+
private void imageGrid_MouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
516+
{
517+
System.Windows.Point point = e.GetPosition(imageGrid);
518+
bool zoomOut = e.Delta < 0;
519+
520+
double scale = 0.75;
521+
if (zoomOut)
522+
scale = 1.0 / scale;
523+
524+
double leftFrac = point.X / image.ActualWidth;
525+
double topFrac = point.Y / image.ActualHeight;
526+
double w = image.ActualWidth * scale;
527+
double h = image.ActualHeight * scale;
528+
double l = point.X - leftFrac * w;
529+
double t = point.Y - topFrac * h;
530+
531+
// NOTE: Currently it's possible to zoom out further than the default zoom
532+
m_zoomBox.Zoom(l, t, w, h, image.ActualWidth, image.ActualHeight);
533+
534+
UpdateItems(false);
535+
}
514536
}
515537
}

Visual_Studio_2015/GraphicalDebugging/PlotWatchControl.xaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
<RowDefinition Height="Auto" />
1616
<RowDefinition Height="0.5*" />
1717
</Grid.RowDefinitions>
18-
<Grid x:Name="imageGrid" Background="Transparent" Cursor="Cross" MouseDown="imageGrid_MouseDown" MouseMove="imageGrid_MouseMove" MouseUp="imageGrid_MouseUp" MouseLeave="imageGrid_MouseLeave" >
18+
<Grid x:Name="imageGrid" Background="Transparent" Cursor="Cross"
19+
MouseDown="imageGrid_MouseDown"
20+
MouseMove="imageGrid_MouseMove"
21+
MouseUp="imageGrid_MouseUp"
22+
MouseLeave="imageGrid_MouseLeave"
23+
MouseWheel="imageGrid_MouseWheel" >
1924
<Image x:Name="image" Stretch="Fill" Height="Auto" Width="Auto" />
2025
<Canvas x:Name="imageCanvas" Height="Auto" Width="Auto" />
2126
</Grid>

Visual_Studio_2015/GraphicalDebugging/PlotWatchControl.xaml.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,5 +527,27 @@ private void imageGrid_MouseLeave(object sender, System.Windows.Input.MouseEvent
527527
m_mouseHLine.Visibility = Visibility.Hidden;
528528
m_mouseTxt.Visibility = Visibility.Hidden;
529529
}
530+
531+
private void imageGrid_MouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
532+
{
533+
System.Windows.Point point = e.GetPosition(imageGrid);
534+
bool zoomOut = e.Delta < 0;
535+
536+
double scale = 0.75;
537+
if (zoomOut)
538+
scale = 1.0 / scale;
539+
540+
double leftFrac = point.X / image.ActualWidth;
541+
double topFrac = point.Y / image.ActualHeight;
542+
double w = image.ActualWidth * scale;
543+
double h = image.ActualHeight * scale;
544+
double l = point.X - leftFrac * w;
545+
double t = point.Y - topFrac * h;
546+
547+
// NOTE: Currently it's possible to zoom out further than the default zoom
548+
m_zoomBox.Zoom(l, t, w, h, image.ActualWidth, image.ActualHeight);
549+
550+
UpdateItems(false);
551+
}
530552
}
531553
}

0 commit comments

Comments
 (0)