Skip to content

Commit

Permalink
Automated JetBrains cleanup
Browse files Browse the repository at this point in the history
Co-authored-by:  <+@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Nov 20, 2024
1 parent bce6309 commit 67e26ed
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 96 deletions.
118 changes: 60 additions & 58 deletions src/Consolonia.Core/Drawing/ConsoleBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,66 +100,68 @@ public static ConsoleBrush FromPosition(IBrush brush, int x, int y, int width, i
switch (brush)
{
case ILinearGradientBrush gradientBrush:
{
if (width <= 0)
width = 1;
if (height <= 0)
height = 1;
// Calculate the relative position within the gradient
double horizontalRelativePosition = (double)x / width;
double verticalRelativePosition = (double)y / height;

// Interpolate horizontal and vertical colors
Color horizontalColor = InterpolateColor(gradientBrush, horizontalRelativePosition);
Color verticalColor = InterpolateColor(gradientBrush, verticalRelativePosition);

// Average the two colors to get the final color
Color color = BlendColors(horizontalColor, verticalColor);
return new ConsoleBrush(color);
}
{
if (width <= 0)
width = 1;
if (height <= 0)
height = 1;
// Calculate the relative position within the gradient
double horizontalRelativePosition = (double)x / width;
double verticalRelativePosition = (double)y / height;

// Interpolate horizontal and vertical colors
Color horizontalColor = InterpolateColor(gradientBrush, horizontalRelativePosition);
Color verticalColor = InterpolateColor(gradientBrush, verticalRelativePosition);

// Average the two colors to get the final color
Color color = BlendColors(horizontalColor, verticalColor);
return new ConsoleBrush(color);
}
case IRadialGradientBrush radialBrush:
{
// Calculate the normalized center coordinates
double centerX = radialBrush.Center.Point.X * width;
double centerY = radialBrush.Center.Point.Y * height;

// Calculate the distance from the center
double dx = x - centerX;
double dy = y - centerY;

// Calculate the distance based on separate X and Y radii
double distanceX = dx / (width * radialBrush.RadiusX.Scalar);
double distanceY = dy / (height * radialBrush.RadiusY.Scalar);
double distance = Math.Sqrt(distanceX * distanceX + distanceY * distanceY);

// Normalize the distance
double normalizedDistance = distance / Math.Sqrt(radialBrush.RadiusX.Scalar * radialBrush.RadiusX.Scalar + radialBrush.RadiusY.Scalar * radialBrush.RadiusY.Scalar);

// Clamp the normalized distance to [0, 1]
normalizedDistance = Math.Min(Math.Max(normalizedDistance, 0), 1);

// Interpolate the color based on the normalized distance
Color color = InterpolateColor(radialBrush, normalizedDistance);
return new ConsoleBrush(color);
}
{
// Calculate the normalized center coordinates
double centerX = radialBrush.Center.Point.X * width;
double centerY = radialBrush.Center.Point.Y * height;

// Calculate the distance from the center
double dx = x - centerX;
double dy = y - centerY;

// Calculate the distance based on separate X and Y radii
double distanceX = dx / (width * radialBrush.RadiusX.Scalar);
double distanceY = dy / (height * radialBrush.RadiusY.Scalar);
double distance = Math.Sqrt(distanceX * distanceX + distanceY * distanceY);

// Normalize the distance
double normalizedDistance = distance /
Math.Sqrt(radialBrush.RadiusX.Scalar * radialBrush.RadiusX.Scalar +
radialBrush.RadiusY.Scalar * radialBrush.RadiusY.Scalar);

// Clamp the normalized distance to [0, 1]
normalizedDistance = Math.Min(Math.Max(normalizedDistance, 0), 1);

// Interpolate the color based on the normalized distance
Color color = InterpolateColor(radialBrush, normalizedDistance);
return new ConsoleBrush(color);
}
case IConicGradientBrush conicBrush:
{
if (width <= 0)
width = 1;
if (height <= 0)
height = 1;
// Calculate the relative position within the gradient
double horizontalRelativePosition = (double)x / width;
double verticalRelativePosition = (double)y / height;

// Interpolate horizontal and vertical colors
Color horizontalColor = InterpolateColor(conicBrush, horizontalRelativePosition);
Color verticalColor = InterpolateColor(conicBrush, verticalRelativePosition);

// Average the two colors to get the final color
Color color = BlendColors(horizontalColor, verticalColor);
return new ConsoleBrush(color);
}
{
if (width <= 0)
width = 1;
if (height <= 0)
height = 1;
// Calculate the relative position within the gradient
double horizontalRelativePosition = (double)x / width;
double verticalRelativePosition = (double)y / height;

// Interpolate horizontal and vertical colors
Color horizontalColor = InterpolateColor(conicBrush, horizontalRelativePosition);
Color verticalColor = InterpolateColor(conicBrush, verticalRelativePosition);

// Average the two colors to get the final color
Color color = BlendColors(horizontalColor, verticalColor);
return new ConsoleBrush(color);
}

default:
return FromBrush(brush);
Expand Down
34 changes: 17 additions & 17 deletions src/Consolonia.Core/Drawing/DrawingContextImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public DrawingContextImpl(ConsoleWindow consoleWindow, PixelBuffer pixelBuffer)

private Rect CurrentClip => _clipStack.Peek();

public RenderOptions RenderOptions { get; set; }

public void Dispose()
{
}
Expand Down Expand Up @@ -291,14 +293,27 @@ public object GetFeature(Type t)
throw new NotImplementedException();
}

public RenderOptions RenderOptions { get; set; }

public Matrix Transform
{
get => _transform;
set => _transform = value * _postTransform;
}

public void DrawRegion(IBrush brush, IPen pen, IPlatformRenderInterfaceRegion region)
{
throw new NotImplementedException();
}

public void PushLayer(Rect bounds)
{
throw new NotImplementedException();
}

public void PopLayer()
{
throw new NotImplementedException();
}

/// <summary>
/// Draw a straight horizontal line or vertical line
/// </summary>
Expand Down Expand Up @@ -780,20 +795,5 @@ private static double GetColorBrightness(SKColor color)
{
return 0.299 * color.Red + 0.587 * color.Green + 0.114 * color.Blue + color.Alpha;
}

public void DrawRegion(IBrush brush, IPen pen, IPlatformRenderInterfaceRegion region)
{
throw new NotImplementedException();
}

public void PushLayer(Rect bounds)
{
throw new NotImplementedException();
}

public void PopLayer()
{
throw new NotImplementedException();
}
}
}
10 changes: 5 additions & 5 deletions src/Consolonia.Core/Drawing/Line.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public bool TryGetSegment(double startDistance, double stopDistance, bool startO
public IGeometryImpl SourceGeometry { get; }
public Matrix Transform { get; }

public IGeometryImpl GetWidenedGeometry(IPen pen)
{
throw new NotImplementedException();
}

public static Line CreateMyLine(Point p1, Point p2)
{
(double x, double y) = p2 - p1;
Expand All @@ -105,10 +110,5 @@ public static Line CreateMyLine(Point p1, Point p2)
// ReSharper disable once PatternIsRedundant todo: fix
return x is 0 or 0d ? new Line(p1, true, (int)y) : new Line(p1, false, (int)x);
}

public IGeometryImpl GetWidenedGeometry(IPen pen)
{
throw new NotImplementedException();
}
}
}
12 changes: 6 additions & 6 deletions src/Consolonia.Core/Infrastructure/ConsoleWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,16 @@ public object TryGetFeature(Type featureType)
if (featureType == typeof(ITextInputMethodImpl)) return null;

Debug.WriteLine($"Someone asked for {featureType.Name}");

// this is a TRY function, so we return null if we don't support it.
return null;
}

public void GetWindowsZOrder(Span<Window> windows, Span<long> zOrder)
{
throw new NotImplementedException();
}

private void ConsoleOnMouseEvent(RawPointerEventType type, Point point, Vector? wheelDelta,
RawInputModifiers modifiers)
{
Expand Down Expand Up @@ -374,10 +379,5 @@ await Dispatcher.UIThread.InvokeAsync(() =>
}, DispatcherPriority.Input);
}
}

public void GetWindowsZOrder(Span<Window> windows, Span<long> zOrder)
{
throw new NotImplementedException();
}
}
}
10 changes: 5 additions & 5 deletions src/Consolonia.Core/Infrastructure/ConsoloniaPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public ITrayIconImpl CreateTrayIcon()
throw new NotImplementedException();
}

public ITopLevelImpl CreateEmbeddableTopLevel()
{
throw new NotImplementedException();
}

public void Initialize()
{
NotSupported += InternalIgnore;
Expand Down Expand Up @@ -80,11 +85,6 @@ notSupportedRequest.Information[1] is null &&
break;
}
}

public ITopLevelImpl CreateEmbeddableTopLevel()
{
throw new NotImplementedException();
}
}

public class ConsoloniaPlatformSettings : DefaultPlatformSettings
Expand Down
11 changes: 6 additions & 5 deletions src/Consolonia.Core/Text/FontManagerImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,20 @@ public bool TryCreateGlyphTypeface(string familyName, FontStyle style, FontWeigh
return true;
}

public bool TryCreateGlyphTypeface(Stream stream, out IGlyphTypeface glyphTypeface)
public bool TryCreateGlyphTypeface(Stream stream, FontSimulations fontSimulations,
[NotNullWhen(true)] out IGlyphTypeface glyphTypeface)
{
throw new NotImplementedException();
}

public static string GetTheOnlyFontFamilyName()
public bool TryCreateGlyphTypeface(Stream stream, out IGlyphTypeface glyphTypeface)
{
return "ConsoleDefault(F7D6533C-AC9D-4C4A-884F-7719A9B5DC0C)";
throw new NotImplementedException();
}

public bool TryCreateGlyphTypeface(Stream stream, FontSimulations fontSimulations, [NotNullWhen(true)] out IGlyphTypeface glyphTypeface)
public static string GetTheOnlyFontFamilyName()
{
throw new NotImplementedException();
return "ConsoleDefault(F7D6533C-AC9D-4C4A-884F-7719A9B5DC0C)";
}
}
}

0 comments on commit 67e26ed

Please sign in to comment.