Skip to content

Commit

Permalink
Live update fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mgth committed Mar 3, 2016
1 parent b5f9b6f commit 24af8fc
Show file tree
Hide file tree
Showing 12 changed files with 213 additions and 92 deletions.
1 change: 1 addition & 0 deletions LittleBigMouse_Control/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<Application.Resources>
<local:BoolToVisibilityConverter x:Key="ToVisibilityConverter" TrueValue="Visible" FalseValue="Hidden"/>
<local:ScaleConverter x:Key="Scale" />
<local:MultiScaleConverter x:Key="MultiScale" />


<Viewbox x:Key="LogoAcer" x:Shared="false" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stretch="Uniform">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
<Button MinWidth="50" Margin="10,0,0,0" Command="{Binding CmdOk}">Ok</Button>
<Button MinWidth="50" Margin="5,0,0,0" Command="{Binding CmdApply}">Apply</Button>
<Button MinWidth="50" Margin="5,0,0,0" Command="{Binding CmdCancel}">Cancel</Button>-->
<Button MinWidth="50" Margin="5,0,0,0" Command="{Binding StartStopCommand}" Content="{Binding StartStopLabel, FallbackValue=Start}"/>
<Button MinWidth="50" Margin="5,0,0,0" Command="{Binding StartCommand}" Content="{Binding StartStopLabel, FallbackValue=Apply/Start}"/>
<Button MinWidth="50" Margin="5,0,0,0" Command="{Binding StopCommand}" Content="{Binding StartStopLabel, FallbackValue=Stop}"/>
<Button MinWidth="50" Margin="5,0,0,0" Command="{Binding SaveCommand}">Save</Button>
</StackPanel>

Expand Down
92 changes: 85 additions & 7 deletions LittleBigMouse_Control/LocationPlugin/LocationControlViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,53 @@ public ScreenConfig Config
if (SetAndWatch(ref _config, value))
{
SaveCommand = new SaveCommand(Config);
StartStopCommand = new StartStopCommand();
StartCommand = new StartCommand(Config);
StopCommand = new StopCommand(Config);
LittleBigMouseClient.Client.StateChanged += Client_StateChanged;
}
}
}

private void Client_StateChanged()
{
Running = LittleBigMouseClient.Client.Running();
}

public String StatStopLabel => LittleBigMouseClient.Client.Running()?"Stop":"Start";

public SaveCommand SaveCommand { get; private set; }
public StartStopCommand StartStopCommand { get; private set; }
public StartCommand StartCommand { get; private set; }
public StopCommand StopCommand { get; private set; }
private ScreenConfig _config;
private bool _showRulers;

private bool _showRulers;
public bool ShowRulers
{
get { return _showRulers; }
set { SetProperty(ref _showRulers,value); }
}

private bool _running;
public bool Running
{
get { return _running; }
private set { SetProperty(ref _running, value); }
}
private bool _liveUpdate;
public bool LiveUpdate
{
get { return _liveUpdate; }
set { SetProperty(ref _liveUpdate, value); }
}
[DependsOn(nameof(LiveUpdate), "Config.Saved")]
private void DoLiveUpdate()
{
if (LiveUpdate && !Config.Saved)
{
StartCommand.Execute(null);
}
}

private readonly List<Ruler> _rulers = new List<Ruler>();
private void AddRuler(RulerSide side)
{
Expand Down Expand Up @@ -102,20 +131,27 @@ public void Execute(object parameter)
#endregion
}

class StartStopCommand : ICommand
class StartCommand : ICommand
{
//private readonly ScreenConfig _config;
private readonly ScreenConfig _config;

public StartCommand(ScreenConfig config)
{
_config = config;
LittleBigMouseClient.Client.StateChanged += Client_StateChanged;
}

public StartStopCommand(/*ScreenConfig config*/)
private void Client_StateChanged()
{
//_config = config;
//CanExecuteChanged?.Invoke(this,null);
}

#region ICommand Members

public bool CanExecute(object parameter)
{
return true;
//return !LittleBigMouseClient.Client.Running();
}

public event EventHandler CanExecuteChanged;
Expand All @@ -124,7 +160,49 @@ public void Execute(object parameter)
//if (!LittleBigMouseClient.Client.Running())
// LittleBigMouseClient.Client.Stop();
//else
if (!_config.Saved) _config.Save();

if (!LittleBigMouseClient.Client.Running())
LittleBigMouseClient.Client.Start();
else
{
_config.Save();
LittleBigMouseClient.Client.LoadConfig();
}
}
#endregion
}

class StopCommand : ICommand
{
private readonly ScreenConfig _config;

public StopCommand(ScreenConfig config)
{
_config = config;
LittleBigMouseClient.Client.StateChanged += Client_StateChanged;
}

private void Client_StateChanged()
{
//CanExecuteChanged?.Invoke(this,null);
}

#region ICommand Members

public bool CanExecute(object parameter)
{
return true;
//return !LittleBigMouseClient.Client.Running();
}

public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
//if (!LittleBigMouseClient.Client.Running())
// LittleBigMouseClient.Client.Stop();
//else
LittleBigMouseClient.Client.Stop();
}
#endregion
}
Expand Down
21 changes: 15 additions & 6 deletions LittleBigMouse_Control/LocationPlugin/LocationScreenView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
MouseMove="OnMouseMove"
d:DesignHeight="300" d:DesignWidth="300"
x:Name="UserControl"
FontSize="{Binding Path=ActualHeight, ElementName=UserControl, Converter={StaticResource Scale},ConverterParameter=0.05}"
>
<!--FontSize="{Binding Path=ActualHeight, ElementName=UserControl, Converter={StaticResource Scale},ConverterParameter=0.05}"-->
<UserControl.FontSize>
<MultiBinding Converter="{StaticResource MultiScale}" ConverterParameter="0.05">
<Binding ElementName="UserControl" Path="ActualHeight"/>
<Binding ElementName="UserControl" Path="ActualWidth"/>
</MultiBinding>
</UserControl.FontSize>

<UserControl.Resources>
<LinearGradientBrush x:Key="ScreenColor" StartPoint="0,0.3" EndPoint="1,0.7">
Expand All @@ -30,22 +36,26 @@
</LinearGradientBrush>
<local:BoolToBrushConverter x:Key="Highlighter" TrueValue="{StaticResource SelectedBrush}" FalseValue="{StaticResource UnselectedBrush}"/>
<local:BoolToVisibilityConverter x:Key="ToVisibilityConverter" TrueValue="Visible" FalseValue="Hidden"/>
<local:ScaleConverter x:Key="Scale" />
</UserControl.Resources>

<Grid x:Name="grid" SizeChanged="OnSizeChanged">
<Grid x:Name="grid" >

<Border BorderThickness="0" Background="{StaticResource ScreenColor}"/>
<!-- Central Device No -->
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Border x:Name="center"
Height ="100"
Width ="100"
Width ="{Binding ElementName=center, Path=Height}"
BorderThickness = "{Binding Path=ActualHeight, ElementName=center, Converter={StaticResource Scale},ConverterParameter=0.05}"
CornerRadius= "{Binding Path=ActualHeight, ElementName=center, Converter={StaticResource Scale},ConverterParameter=0.5}"

Background="{Binding Screen.Selected, Converter={StaticResource Highlighter}, FallbackValue={StaticResource UnselectedBrush}}"
BorderBrush="#FFD9DCEC">
<Border.Height>
<MultiBinding Converter="{StaticResource MultiScale}" ConverterParameter="0.3">
<Binding ElementName="UserControl" Path="ActualHeight"/>
<Binding ElementName="UserControl" Path="ActualWidth"/>
</MultiBinding>
</Border.Height>
<Label
FontSize="{Binding Path=ActualHeight, ElementName=center, Converter={StaticResource Scale},ConverterParameter=0.5}"
x:Name="lblName"
Expand Down Expand Up @@ -143,7 +153,6 @@


<Label
FontSize="{Binding Path=ActualHeight, ElementName=grid, Converter={StaticResource Scale},ConverterParameter=0.05}"
Content="{Binding Path=Screen.RealDpiAvg, FallbackValue=96}"
ContentStringFormat="#0" VerticalAlignment="{Binding Path=DpiVerticalAlignment}"
HorizontalAlignment="Right"
Expand Down
48 changes: 26 additions & 22 deletions LittleBigMouse_Control/LocationPlugin/LocationScreenView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ partial class LocationScreenView : UserControl
public LocationScreenView()
{
InitializeComponent();
SizeChanged += OnSizeChanged1;
LayoutUpdated += View_LayoutUpdated;
//LayoutUpdated += View_LayoutUpdated;
SizeChanged += View_LayoutUpdated;
}

// private ScreenConfig Config => MainViewModel.Instance.Config;
Expand All @@ -52,35 +52,19 @@ private void View_LayoutUpdated(object sender, EventArgs e)
{
if (_staticPoint != null)
{
Point p2 = PointToScreen(
Point p = PointToScreen(
new Point(
ActualWidth * _staticPoint.Value.X,
ActualHeight * _staticPoint.Value.Y
));
WinAPI_User32.User32.SetCursorPos((int)p2.X, (int)p2.Y);

WinAPI_User32.User32.SetCursorPos((int)p.X, (int)p.Y);

_staticPoint = null;
}
}

private void OnSizeChanged1(object sender, SizeChangedEventArgs sizeChangedEventArgs)
{
((ScreenViewModel)DataContext).RaiseProperty("Size");
}

private LocationScreenViewModel ViewModel => (DataContext as LocationScreenViewModel);

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnSizeChanged(object sender, SizeChangedEventArgs e)
{
double size = Math.Min(grid.ActualHeight, grid.ActualWidth) / 3;
center.Height = size;
center.Width = size;
}
private LocationScreenViewModel ViewModel => (DataContext as LocationScreenViewModel);


private void PhysicalWidth_MouseWheel(object sender, MouseWheelEventArgs e)
Expand Down Expand Up @@ -193,4 +177,24 @@ public object ConvertBack(object value, Type targetType, object parameter, Syste

}

public class MultiScaleConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
double v = double.MaxValue;
foreach (object value in values)
{
if (value is double && (double)value < v) v = (double) value;
}

double scale = double.Parse((string)parameter, CultureInfo.InvariantCulture);

return Math.Max(v * scale, 0.1);
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
8 changes: 0 additions & 8 deletions LittleBigMouse_Control/ScreenFrameViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,6 @@ private void UpdateMargin(string s)
[DependsOn("Screen.BottomBorder", "Presenter.Ratio")]
public GridLength BottomBorder => new GridLength(Screen.BottomBorder * Presenter.Ratio);


[DependsOn("BottomBorder")]
public double BottomFontSize => Math.Max(MinFontSize, BottomBorder.Value * 0.6);


[DependsOn("LeftBorder")]
public double LeftFontSize => Math.Max(MinFontSize, LeftBorder.Value * 0.6);

[DependsOn("Screen.LeftBorder", "Presenter.Ratio")]
public GridLength LeftBorder => new GridLength(Screen.LeftBorder * Presenter.Ratio);

Expand Down
19 changes: 0 additions & 19 deletions LittleBigMouse_Control/ScreenViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public double PhysicalOutsideHeight
{
double offset = value - PhysicalOutsideHeight;
Screen.RealBottomBorder += offset;
Screen.Config.Compact();
}
}

Expand All @@ -53,7 +52,6 @@ public double PhysicalOutsideWidth
double offset = (value - PhysicalOutsideWidth) / 2;
Screen.RealLeftBorder += offset;
Screen.RealRightBorder += offset;
Screen.Config.Compact();
}
}

Expand All @@ -65,25 +63,8 @@ public double PhysicalOutsideWidth



protected const double MinFontSize = 0.1;

private double _fontSize = MinFontSize;
public static DependencyProperty ScreenProperty = DependencyProperty.Register(nameof(Screen), typeof(Screen), typeof(ScreenViewModel), WatchNotifier());

public double FontSize
{
get { return _fontSize; }
private set { SetProperty(ref _fontSize, value); }
}

public void OnSizeChanged(object sender, SizeChangedEventArgs sizeChangedEventArgs)
{
var obj = sender as UserControl;
if (obj != null)
{
double s = Math.Min(obj.ActualHeight, obj.ActualWidth) / 7;
FontSize = Math.Max(MinFontSize, Math.Pow(s, 1 / 1.3));
}
}
}
}
Loading

0 comments on commit 24af8fc

Please sign in to comment.