Skip to content

Commit

Permalink
Добавлена возможность дискретного изменения геометрических параметров
Browse files Browse the repository at this point in the history
  • Loading branch information
ComradeAkei committed Nov 11, 2023
1 parent be6eb29 commit 1040862
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
5 changes: 4 additions & 1 deletion MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
<gif:GifImage Name="LoadingGif" IsVisible="False" SourceUriRaw="{Binding Path=SelectedGif}"
Stretch="None"
StretchDirection="Both" />
<TextBlock Name="TEST_text" Text=""/>
<CheckBox Name="StrictModeEnabled" IsChecked="False" >Строгий режим</CheckBox>
<TextBox Name="StrictModeValue" Text="1" Margin="5,0,0,0"
PropertyChanged="StrictModeEnabled_OnPropertyChanged" VerticalAlignment="Center" HorizontalAlignment="Center"
VerticalContentAlignment="Center"/>

</StackPanel>

Expand Down
8 changes: 4 additions & 4 deletions MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ private void jCanvas_OnPointerMoved(object? sender, PointerEventArgs e)

if (movable.IsPressed && !LCtrlPressed)
{
Canvas.SetLeft(element, mousePosition.X - mov_hw);
Canvas.SetTop(element, mousePosition.Y - mov_hh);
Canvas.SetLeft(element, CorrectCoords(mousePosition.X - mov_hw));
Canvas.SetTop(element, CorrectCoords(mousePosition.Y - mov_hh));

if (Canvas.GetLeft(element) < 0)
Canvas.SetLeft(element, 0);
Expand All @@ -138,8 +138,8 @@ private void jCanvas_OnPointerMoved(object? sender, PointerEventArgs e)
mousePosition = e.GetPosition(element);
if(mousePosition.X<5 || mousePosition.Y<5)
return;
element.Width = mousePosition.X;
element.Height = mousePosition.Y;
element.Width = CorrectSize(mousePosition.X);
element.Height = CorrectSize(mousePosition.Y);
}
}

Expand Down
27 changes: 26 additions & 1 deletion Miscellaneous.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,33 @@ public void AddPropItem(string name, object? value,Type type)

private SolidColorBrush GetColor(string color)
=> new SolidColorBrush(Color.Parse(color));


//Корректировка координат для перемещения и растяжения в строгом режиме
double CorrectCoords(double coord)
{
if ((bool)!StrictModeEnabled.IsChecked) return coord;
if(StrictModeValue.Text == "") return coord;
int step = Convert.ToInt32(StrictModeValue.Text);
if (step <= 0) return coord;
var _coord = (((int)coord)/step)*step;
return _coord;

}
double CorrectSize(double coord)
=> CorrectCoords(coord)>0?CorrectCoords(coord):Convert.ToInt32(StrictModeValue.Text);


private void StrictModeEnabled_OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
{
if (StrictModeValue == null) return;
try
{
var value = Convert.ToInt32(StrictModeValue.Text);
StrictModeValue.Text = Math.Abs(value).ToString();
}
catch
{
StrictModeValue.Text = "";
}
}
}
Binary file modified bin/Debug/net8.0/Xamlade.dll
Binary file not shown.
Binary file modified bin/Debug/net8.0/Xamlade.pdb
Binary file not shown.

0 comments on commit 1040862

Please sign in to comment.