Color picker done

This commit is contained in:
Иван Ивашкин
2024-12-05 00:02:37 +05:00
parent bcea9639f6
commit 8205dafdbd
9 changed files with 119 additions and 18 deletions

View File

@@ -149,14 +149,29 @@
<RowDefinition Height="30"/> <RowDefinition Height="30"/>
<RowDefinition Height="30"/> <RowDefinition Height="30"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Grid.Row="0" <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0"
Margin="5" Margin="5"
Text="Color:" Text="Color:"
VerticalAlignment="Center"/> VerticalAlignment="Center"/>
<ComboBox Grid.Row="1" <Button Grid.Row="1"
Margin="5" Grid.Column="1"
ItemsSource="{Binding Colors}" Margin="5,5,5,5"
SelectedItem="{Binding CurrentColor}"/> Command="{Binding EditColorCommand}"
Content="Press to change color">
</Button>
<Rectangle
Grid.Row="1"
Grid.Column="0"
Margin="5,5,5,5">
<Rectangle.Fill>
<SolidColorBrush Color="{Binding Color, UpdateSourceTrigger=PropertyChanged}"/>
</Rectangle.Fill>
</Rectangle>
</Grid> </Grid>
<Button Grid.Row="7" Margin="5" Content="Save" <Button Grid.Row="7" Margin="5" Content="Save"
Command="{Binding SaveCommand}" Command="{Binding SaveCommand}"

View File

@@ -2,6 +2,7 @@
using StructureHelper.Infrastructure; using StructureHelper.Infrastructure;
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Functions; using StructureHelperCommon.Models.Functions;
using StructureHelperCommon.Services.ColorServices;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@@ -30,6 +31,7 @@ namespace StructureHelper.Windows.MainGraph
public char LESS { get; } = '\u2264'; public char LESS { get; } = '\u2264';
public char X { get; } = 'x'; public char X { get; } = 'x';
private RelayCommand saveCommand; private RelayCommand saveCommand;
private RelayCommand editColor;
public int Step { get; set; } public int Step { get; set; }
private double leftBound; private double leftBound;
public double LeftBound public double LeftBound
@@ -53,8 +55,11 @@ namespace StructureHelper.Windows.MainGraph
OnPropertyChanged(nameof(RightBound)); OnPropertyChanged(nameof(RightBound));
} }
} }
public Color CurrentColor { get; set; }
public ObservableCollection<Color> Colors { get; set; } public ObservableCollection<Color> Colors { get; set; }
public ICommand EditColorCommand
{
get => editColor ??= new RelayCommand(o => EditColor());
}
public ICommand SaveCommand public ICommand SaveCommand
{ {
get => saveCommand ??= new RelayCommand(o => Save(o)); get => saveCommand ??= new RelayCommand(o => Save(o));
@@ -107,6 +112,16 @@ namespace StructureHelper.Windows.MainGraph
description = value; description = value;
} }
} }
private Color color;
public Color Color
{
get => color;
set
{
color = value;
OnPropertyChanged(nameof(Color));
}
}
private string limitText; private string limitText;
public string LimitText public string LimitText
{ {
@@ -125,7 +140,7 @@ namespace StructureHelper.Windows.MainGraph
LeftBound = DEFAULT_LEFT_BOUND; LeftBound = DEFAULT_LEFT_BOUND;
RightBound = DEFAULT_RIGHT_BOUND; RightBound = DEFAULT_RIGHT_BOUND;
LimitText = $"x\u2208[{LeftBound};{RightBound}]"; LimitText = $"x\u2208[{LeftBound};{RightBound}]";
CurrentColor = Brushes.AliceBlue.Color; Color = Brushes.Red.Color;
} }
public FormulaViewModel(FormulaFunction formulaFunction) public FormulaViewModel(FormulaFunction formulaFunction)
{ {
@@ -136,7 +151,13 @@ namespace StructureHelper.Windows.MainGraph
Description = Function.Description; Description = Function.Description;
LeftBound = Function.MinArg; LeftBound = Function.MinArg;
RightBound = Function.MaxArg; RightBound = Function.MaxArg;
CurrentColor = Function.Color; Color = Function.Color;
}
private void EditColor()
{
Color color = new Color();
ColorProcessor.EditColor(ref color);
Color = color;
} }
private void Save(object parameter) private void Save(object parameter)
{ {
@@ -149,6 +170,7 @@ namespace StructureHelper.Windows.MainGraph
Function.IsUser = true; Function.IsUser = true;
(Function as FormulaFunction).Step = Step; (Function as FormulaFunction).Step = Step;
(Function as FormulaFunction).Formula = Formula; (Function as FormulaFunction).Formula = Formula;
Function.Color = Color;
var window = parameter as Window; var window = parameter as Window;
if (LeftBound > RightBound) if (LeftBound > RightBound)
{ {

View File

@@ -63,7 +63,17 @@
</ListView.GroupStyle> </ListView.GroupStyle>
<ListView.ItemTemplate> <ListView.ItemTemplate>
<DataTemplate> <DataTemplate>
<StackPanel Orientation="Horizontal">
<Rectangle
Margin="1,1,1,1"
Height="15"
Width="30">
<Rectangle.Fill>
<SolidColorBrush Color="{Binding Path=Color, UpdateSourceTrigger=PropertyChanged}"/>
</Rectangle.Fill>
</Rectangle>
<TextBlock Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}"/> <TextBlock Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}"/>
</StackPanel>
</DataTemplate> </DataTemplate>
</ListView.ItemTemplate> </ListView.ItemTemplate>
</ListView> </ListView>

View File

@@ -111,11 +111,29 @@
<RowDefinition Height="30"/> <RowDefinition Height="30"/>
<RowDefinition Height="30"/> <RowDefinition Height="30"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Grid.Row="0" <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0"
Margin="5" Margin="5"
Text="Color:" Text="Color:"
VerticalAlignment="Center"/> VerticalAlignment="Center"/>
<ComboBox Grid.Row="1" Text="{Binding Description}" Margin="5"/> <Button Grid.Row="1"
Grid.Column="1"
Margin="5,5,5,5"
Command="{Binding EditColorCommand}"
Content="Press to change color">
</Button>
<Rectangle
Grid.Row="1"
Grid.Column="0"
Margin="5,5,5,5">
<Rectangle.Fill>
<SolidColorBrush Color="{Binding Color, UpdateSourceTrigger=PropertyChanged}"/>
</Rectangle.Fill>
</Rectangle>
</Grid> </Grid>
<Button Grid.Row="6" Margin="5" Content="Save" <Button Grid.Row="6" Margin="5" Content="Save"
Command="{Binding SaveCommand}" Command="{Binding SaveCommand}"

View File

@@ -2,6 +2,7 @@
using StructureHelperCommon.Infrastructures.Interfaces; using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Functions; using StructureHelperCommon.Models.Functions;
using StructureHelperCommon.Models.Shapes; using StructureHelperCommon.Models.Shapes;
using StructureHelperCommon.Services.ColorServices;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@@ -11,6 +12,7 @@ using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media;
namespace StructureHelper.Windows.MainGraph namespace StructureHelper.Windows.MainGraph
{ {
@@ -21,6 +23,11 @@ namespace StructureHelper.Windows.MainGraph
private RelayCommand saveCommand; private RelayCommand saveCommand;
private RelayCommand addPointCommand; private RelayCommand addPointCommand;
private RelayCommand deletePointCommand; private RelayCommand deletePointCommand;
private RelayCommand editColor;
public ICommand EditColorCommand
{
get => editColor ??= new RelayCommand(o => EditColor());
}
public ICommand SaveCommand public ICommand SaveCommand
{ {
get => saveCommand ??= new RelayCommand(o => Save(o)); get => saveCommand ??= new RelayCommand(o => Save(o));
@@ -81,6 +88,16 @@ namespace StructureHelper.Windows.MainGraph
description = value; description = value;
} }
} }
private Color color;
public Color Color
{
get => color;
set
{
color = value;
OnPropertyChanged(nameof(Color));
}
}
public TableViewModel() public TableViewModel()
{ {
Table = new ObservableCollection<GraphPoint>() Table = new ObservableCollection<GraphPoint>()
@@ -90,6 +107,7 @@ namespace StructureHelper.Windows.MainGraph
}; };
Name = DEFAULT_NAME; Name = DEFAULT_NAME;
Description = DEFAULT_DESCRIPTION; Description = DEFAULT_DESCRIPTION;
Color = Brushes.Red.Color;
} }
public TableViewModel(TableFunction tableFunction) public TableViewModel(TableFunction tableFunction)
{ {
@@ -97,6 +115,13 @@ namespace StructureHelper.Windows.MainGraph
Table = new ObservableCollection<GraphPoint>((Function as TableFunction).Table); Table = new ObservableCollection<GraphPoint>((Function as TableFunction).Table);
Name = Function.Name; Name = Function.Name;
Description = Function.Description; Description = Function.Description;
Color = Function.Color;
}
private void EditColor()
{
Color color = new Color();
ColorProcessor.EditColor(ref color);
Color = color;
} }
private void Save(object parameter) private void Save(object parameter)
{ {
@@ -108,6 +133,7 @@ namespace StructureHelper.Windows.MainGraph
Function.Description = Description; Function.Description = Description;
Function.IsUser = true; Function.IsUser = true;
(Function as TableFunction).Table = Table.OrderBy(x => x.X).ToList(); (Function as TableFunction).Table = Table.OrderBy(x => x.X).ToList();
Function.Color = Color;
var window = parameter as Window; var window = parameter as Window;
window.DialogResult = true; window.DialogResult = true;
window.Close(); window.Close();

View File

@@ -30,7 +30,14 @@ namespace StructureHelperCommon.Models.Functions.Decorator
{ {
return y; return y;
} }
return 0; else if (y <= downBound)
{
return downBound;
}
else
{
return upBound;
}
} }
public override GraphSettings GetGraphSettings() public override GraphSettings GetGraphSettings()
{ {

View File

@@ -12,6 +12,7 @@ using System.Threading.Tasks;
using System.Windows.Documents; using System.Windows.Documents;
using StructureHelperCommon.Services; using StructureHelperCommon.Services;
using LiveCharts.Wpf; using LiveCharts.Wpf;
using StructureHelperCommon.Services.ColorServices;
namespace StructureHelperCommon.Models.Functions namespace StructureHelperCommon.Models.Functions
{ {
@@ -36,6 +37,7 @@ namespace StructureHelperCommon.Models.Functions
public FormulaFunction(bool isUser = false) public FormulaFunction(bool isUser = false)
{ {
Color = ColorProcessor.GetRandomColor();
Type = FunctionType.FormulaFunction; Type = FunctionType.FormulaFunction;
if (isUser) if (isUser)
{ {

View File

@@ -10,6 +10,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using StructureHelperCommon.Services; using StructureHelperCommon.Services;
using StructureHelperCommon.Services.ColorServices;
namespace StructureHelperCommon.Models.Functions namespace StructureHelperCommon.Models.Functions
{ {
@@ -36,6 +37,7 @@ namespace StructureHelperCommon.Models.Functions
public TableFunction(bool isUser = false) public TableFunction(bool isUser = false)
{ {
Color = ColorProcessor.GetRandomColor();
Type = FunctionType.TableFunction; Type = FunctionType.TableFunction;
if (isUser) if (isUser)
{ {
@@ -48,7 +50,6 @@ namespace StructureHelperCommon.Models.Functions
Group = GROUP_TYPE_1; Group = GROUP_TYPE_1;
} }
} }
public bool Check() public bool Check()
{ {
throw new NotImplementedException(); throw new NotImplementedException();

View File

@@ -40,8 +40,8 @@ namespace StructureHelperCommon.Services
_chartValues.Add(Math.Round(point.Y, 2)); _chartValues.Add(Math.Round(point.Y, 2));
} }
_lineSeries.Values = _chartValues; _lineSeries.Values = _chartValues;
_lineSeries.Stroke = Brushes.Blue; //Заменить на поле Color _lineSeries.Stroke = new SolidColorBrush(_strokeColor);
_lineSeries.Fill = Brushes.Transparent; //Заменить на поле Color _lineSeries.Fill = Brushes.Transparent;
_seriesCollection.Add(_lineSeries); _seriesCollection.Add(_lineSeries);
return _seriesCollection; return _seriesCollection;
} }