Skip to content

Commit

Permalink
used color in preview
Browse files Browse the repository at this point in the history
  • Loading branch information
stany24 committed Oct 1, 2024
1 parent 9286ea8 commit 99ec2eb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
9 changes: 5 additions & 4 deletions BendingCalculator/Database/Actions/DataBaseLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ FROM Material

private static Material LoadMaterial(IDataRecord reader)
{
string? colorHexadecimal = Convert.ToString(reader["Color"]);
byte r = byte.Parse(colorHexadecimal?.Substring(0, 2) ?? "00", System.Globalization.NumberStyles.HexNumber);
byte g = byte.Parse(colorHexadecimal?.Substring(2, 2) ?? "00", System.Globalization.NumberStyles.HexNumber);
byte b = byte.Parse(colorHexadecimal?.Substring(4, 2) ?? "00", System.Globalization.NumberStyles.HexNumber);
string colorHexadecimal = Convert.ToString(reader["Color"]) ?? "ffffff";
if(colorHexadecimal.Length < 6) colorHexadecimal = "ffffff";
byte r = byte.Parse(colorHexadecimal.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
byte g = byte.Parse(colorHexadecimal.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
byte b = byte.Parse(colorHexadecimal.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
Color color = Color.FromRgb(r, g, b);
return new Material
{
Expand Down
2 changes: 2 additions & 0 deletions BendingCalculator/Logic/Math/Material.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ public Material(string name, long e)
{
Name = name;
_e = e;
Color = Colors.White;
}

public Material()
{
Name = "new";
Color = Colors.White;
}

#endregion
Expand Down
9 changes: 5 additions & 4 deletions BendingCalculator/Logic/Preview/LayerPreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,18 @@ private void UpdatePreview()
UpdateLayout();
double width = _grid.ColumnDefinitions[2].ActualWidth - 2 * PreviewMargin;
double height = Bounds.Size.Height - 3 * PreviewMargin;
Color color = (DisplayedLayer.Material ?? new Material()).Color;
List<Shape> shapes = new()
{
GetLayerShape(PreviewMargin, PreviewMargin, width, height / 2,
DisplayedLayer.HeightAtCenter / DisplayedLayer.HeightOnSides),
DisplayedLayer.HeightAtCenter / DisplayedLayer.HeightOnSides,color),
GetLayerShape(PreviewMargin, 2 * PreviewMargin + height / 2, width, height / 2,
DisplayedLayer.WidthAtCenter / DisplayedLayer.WidthOnSides)
DisplayedLayer.WidthAtCenter / DisplayedLayer.WidthOnSides,color)
};
_preview.Children.AddRange(shapes);
}

private static Path GetLayerShape(double x, double y, double width, double height, double proportionCenterOverSides)
private static Path GetLayerShape(double x, double y, double width, double height, double proportionCenterOverSides,Color color)
{
int minusCenter = 0;
int minusSides = 0;
Expand All @@ -129,7 +130,7 @@ private static Path GetLayerShape(double x, double y, double width, double heigh
minusCenter = (int)((height - height * proportionCenterOverSides) / 2);
return new Path
{
Fill = Brushes.LightBlue,
Fill = new SolidColorBrush(color),
Data = new PathGeometry
{
Figures = new PathFigures
Expand Down
8 changes: 5 additions & 3 deletions BendingCalculator/Logic/Preview/PiecePreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,24 @@ private void UpdatePreview()
double horizontalMargin = (width - pieceWidth) / 2;
double pieceHeight = (height - PreviewMargin * (DisplayedPiece.Layers.Count - 1)) *
(DisplayedPiece.Layers[i - 1].HeightOnSides / totalHeight);
Color color = (DisplayedPiece.Layers[i - 1].Material ?? new Material()).Color;
shapes.Add(GetRectangle(
PreviewMargin + horizontalMargin,
PreviewMargin * i + heightOfPiecesBefore,
pieceWidth,
pieceHeight));
pieceHeight,
color));
heightOfPiecesBefore += pieceHeight;
}

_preview.Children.AddRange(shapes);
}

private static Path GetRectangle(double x, double y, double width, double height)
private static Path GetRectangle(double x, double y, double width, double height,Color color)
{
return new Path
{
Fill = Brushes.LightBlue,
Fill = new SolidColorBrush(color),
Data = new PathGeometry
{
Figures = new PathFigures
Expand Down

0 comments on commit 99ec2eb

Please sign in to comment.