Skip to content

Commit

Permalink
Fancy keyboard shortcuts.
Browse files Browse the repository at this point in the history
* Up, Down, Left, Right : Rotate clock plane
* +/- : Zoom in and out
* 0 : Reset all
  • Loading branch information
prodehghan committed Apr 15, 2013
1 parent df999a6 commit 2c792b5
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 1 deletion.
7 changes: 6 additions & 1 deletion SepidarSidebar/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@
<Transform3DGroup>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="0,1,0" Angle="-17" />
<AxisAngleRotation3D Axis="0,1,0" Angle="{Binding Path=VerticalRotationDegree}" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Axis="1,0,0" Angle="{Binding Path=HorizontalRotationDegree}" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
</Transform3DGroup>
Expand Down
55 changes: 55 additions & 0 deletions SepidarSidebar/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ namespace SG.SepidarSidebar
/// </summary>
public partial class MainWindow : Window
{
private MainWindowViewModel _viewModel;
public MainWindow()
{
InitializeComponent();

_viewModel = new MainWindowViewModel();
this.DataContext = _viewModel;
}

protected override void OnMouseDown(MouseButtonEventArgs e)
Expand All @@ -32,5 +36,56 @@ protected override void OnMouseDown(MouseButtonEventArgs e)
if (e.LeftButton == MouseButtonState.Pressed && e.RightButton == MouseButtonState.Released)
this.DragMove();
}

protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);

if (e.Key == Key.D0)
ResetTransforms();
else if (e.Key == Key.OemPlus)
{
double w = this.Width * 1.5;
double sw = SystemParameters.PrimaryScreenWidth, sh = SystemParameters.PrimaryScreenHeight;
if (w > sw || w > sh)
w = Math.Min(sw, sh);
this.Width = this.Height = w;
}
else if (e.Key == Key.OemMinus)
{
if (this.Width > 20)
{
this.Width = this.Height = this.Width / 1.5;
}
}
else if (e.Key == Key.Right)
{
if (_viewModel.VerticalRotationDegree < 50)
_viewModel.VerticalRotationDegree += 5;
}
else if (e.Key == Key.Left)
{
if (_viewModel.VerticalRotationDegree > -50)
_viewModel.VerticalRotationDegree -= 5;
}
else if (e.Key == Key.Down)
{
if (_viewModel.HorizontalRotationDegree < 50)
_viewModel.HorizontalRotationDegree += 5;
}
else if (e.Key == Key.Up)
{
if (_viewModel.HorizontalRotationDegree > -50)
_viewModel.HorizontalRotationDegree -= 5;
}
}

public void ResetTransforms()
{
_viewModel.HorizontalRotationDegree = 0;
_viewModel.VerticalRotationDegree = -17;
Width = 250;
Height = 250;
}
}
}
40 changes: 40 additions & 0 deletions SepidarSidebar/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SG.SepidarSidebar
{
public class MainWindowViewModel : ViewModelBase
{
private double _verticalRotationDegree = -17;
private double _horizontalRotationDegree = 0;

public double VerticalRotationDegree
{
get { return _verticalRotationDegree; }
set
{
if (_verticalRotationDegree != value)
{
_verticalRotationDegree = value;
OnPropertyChanged("VerticalRotationDegree");
}
}
}

public double HorizontalRotationDegree
{
get { return _horizontalRotationDegree; }
set
{
if (_horizontalRotationDegree != value)
{
_horizontalRotationDegree = value;
OnPropertyChanged("HorizontalRotationDegree");
}
}
}

}
}
1 change: 1 addition & 0 deletions SepidarSidebar/SepidarSidebar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="MainWindowViewModel.cs" />
<Compile Include="ViewModelBase.cs" />
<Page Include="ClockControl.xaml">
<SubType>Designer</SubType>
Expand Down

0 comments on commit 2c792b5

Please sign in to comment.