Skip to content

Commit 4814df4

Browse files
committed
more API docs, a couple more extension methods for GraphicsExtensions, and a release candidate for a VN engine
1 parent 4607603 commit 4814df4

File tree

59 files changed

+2170
-566
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2170
-566
lines changed

.claude/settings.local.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(dir:*)"
5+
]
6+
}
7+
}

BenMakesGames.PlayPlayMini.BeepBoop/BenMakesGames.PlayPlayMini.BeepBoop.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Company>Ben Hendel-Doying</Company>
66
<Description>An extension for PlayPlayMini which adds methods for generating &amp; playing simple waveforms.</Description>
77
<Copyright>2022-2024 Ben Hendel-Doying</Copyright>
8-
<Version>0.10.0</Version>
8+
<Version>0.11.0</Version>
99

1010
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1111
<PackageTags>monogame playplaymini sound generation square triangle saw sine wave waveform</PackageTags>

BenMakesGames.PlayPlayMini.GraphicsExtensions/BenMakesGames.PlayPlayMini.GraphicsExtensions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Company>Ben Hendel-Doying</Company>
66
<Description>Some GraphicsManager extensions for PlayPlayMini.</Description>
77
<Copyright>2023-2025 Ben Hendel-Doying</Copyright>
8-
<Version>7.1.0</Version>
8+
<Version>7.2.0</Version>
99

1010
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1111
<PackageTags>monogame playplaymini graphics extensions animations text</PackageTags>

BenMakesGames.PlayPlayMini.GraphicsExtensions/ColorExtensions.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,23 @@ namespace BenMakesGames.PlayPlayMini.GraphicsExtensions;
77
/// </summary>
88
public static class ColorExtensions
99
{
10-
/// <summary>
11-
/// Calculates the relative luminosity of a color using the standard coefficients for RGB to grayscale conversion.
12-
/// </summary>
1310
/// <param name="c">The color to calculate luminosity for.</param>
14-
/// <returns>The relative luminosity value between 0 and 255.</returns>
15-
/// <remarks>
16-
/// Uses the standard coefficients for RGB to grayscale conversion:
17-
/// Red: 0.2126, Green: 0.7152, Blue: 0.0722
18-
/// </remarks>
19-
public static float Luminosity(this Color c) => c.R * 0.2126f + c.G * 0.7152f + c.B * 0.0722f;
11+
extension(Color c)
12+
{
13+
/// <summary>
14+
/// Calculates the relative luminosity of a color using the standard coefficients for RGB to grayscale conversion.
15+
/// </summary>
16+
/// <returns>The relative luminosity value between 0 and 255.</returns>
17+
/// <remarks>
18+
/// Uses the standard coefficients for RGB to grayscale conversion:
19+
/// Red: 0.2126, Green: 0.7152, Blue: 0.0722
20+
/// </remarks>
21+
public float Luminosity() => c.R * 0.2126f + c.G * 0.7152f + c.B * 0.0722f;
2022

21-
/// <summary>
22-
/// Returns either black or white color that provides the best contrast with the given color.
23-
/// </summary>
24-
/// <param name="c">The color to find a contrasting color for.</param>
25-
/// <returns>White if the input color's luminosity is less than 96, Black otherwise.</returns>
26-
public static Color GetContrastingBlackOrWhite(this Color c) => c.Luminosity() < 96 ? Color.White : Color.Black;
23+
/// <summary>
24+
/// Returns either black or white color that provides the best contrast with the given color.
25+
/// </summary>
26+
/// <returns>White if the input color's luminosity is less than 96, Black otherwise.</returns>
27+
public Color GetContrastingBlackOrWhite() => c.Luminosity() < 96 ? Color.White : Color.Black;
28+
}
2729
}

BenMakesGames.PlayPlayMini.GraphicsExtensions/EllipseExtensions.cs

Lines changed: 230 additions & 230 deletions
Large diffs are not rendered by default.

BenMakesGames.PlayPlayMini.GraphicsExtensions/LineExtensions.cs

Lines changed: 101 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -10,122 +10,122 @@ namespace BenMakesGames.PlayPlayMini.GraphicsExtensions;
1010
/// </summary>
1111
public static class LineExtensions
1212
{
13-
/// <summary>
14-
/// Draws a horizontal line from x1 to x2 at height y.
15-
/// </summary>
1613
/// <param name="graphics">The graphics manager instance.</param>
17-
/// <param name="x1">Starting x coordinate.</param>
18-
/// <param name="x2">Ending x coordinate.</param>
19-
/// <param name="y">Y coordinate of the line.</param>
20-
/// <param name="color">Color of the line.</param>
21-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
22-
public static void DrawRow(this GraphicsManager graphics, int x1, int x2, int y, Color color)
23-
=> graphics.DrawFilledRectangle(x1, y, x2 - x1 + 1, 1, color);
24-
25-
/// <summary>
26-
/// Draws a vertical line from y1 to y2 at position x.
27-
/// </summary>
28-
/// <param name="graphics">The graphics manager instance.</param>
29-
/// <param name="x">X coordinate of the line.</param>
30-
/// <param name="y1">Starting y coordinate.</param>
31-
/// <param name="y2">Ending y coordinate.</param>
32-
/// <param name="color">Color of the line.</param>
33-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
34-
public static void DrawColumn(this GraphicsManager graphics, int x, int y1, int y2, Color color)
35-
=> graphics.DrawFilledRectangle(x, y1, 1, y2 - y1 + 1, color);
36-
37-
/// <summary>
38-
/// Draws a line between two Vector2 points.
39-
/// </summary>
40-
/// <param name="graphics">The graphics manager instance.</param>
41-
/// <param name="start">Starting point of the line.</param>
42-
/// <param name="end">Ending point of the line.</param>
43-
/// <param name="color">Color of the line.</param>
44-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
45-
public static void DrawLine(this GraphicsManager graphics, Vector2 start, Vector2 end, Color color)
46-
=> graphics.DrawLine((int)start.X, (int)start.Y, (int)end.X, (int)end.Y, color);
47-
48-
/// <summary>
49-
/// Draws a line between two points using a modified Bresenham's line algorithm.
50-
/// </summary>
51-
/// <remarks>
52-
/// This implementation minimizes MonoGame Draw calls by drawing line segments.
53-
/// </remarks>
54-
/// <param name="graphics">The graphics manager instance.</param>
55-
/// <param name="x1">Starting x coordinate.</param>
56-
/// <param name="y1">Starting y coordinate.</param>
57-
/// <param name="x2">Ending x coordinate.</param>
58-
/// <param name="y2">Ending y coordinate.</param>
59-
/// <param name="color">Color of the line.</param>
60-
public static void DrawLine(this GraphicsManager graphics, int x1, int y1, int x2, int y2, Color color)
14+
extension(GraphicsManager graphics)
6115
{
62-
var w = x2 - x1;
16+
/// <summary>
17+
/// Draws a horizontal line from x1 to x2 at height y.
18+
/// </summary>
19+
/// <param name="x1">Starting x coordinate.</param>
20+
/// <param name="x2">Ending x coordinate.</param>
21+
/// <param name="y">Y coordinate of the line.</param>
22+
/// <param name="color">Color of the line.</param>
23+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
24+
public void DrawRow(int x1, int x2, int y, Color color)
25+
=> graphics.DrawFilledRectangle(x1, y, x2 - x1 + 1, 1, color);
6326

64-
if (w == 0)
65-
{
66-
graphics.DrawColumn(x1, y1, y2, color);
67-
return;
68-
}
27+
/// <summary>
28+
/// Draws a vertical line from y1 to y2 at position x.
29+
/// </summary>
30+
/// <param name="x">X coordinate of the line.</param>
31+
/// <param name="y1">Starting y coordinate.</param>
32+
/// <param name="y2">Ending y coordinate.</param>
33+
/// <param name="color">Color of the line.</param>
34+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
35+
public void DrawColumn(int x, int y1, int y2, Color color)
36+
=> graphics.DrawFilledRectangle(x, y1, 1, y2 - y1 + 1, color);
6937

70-
var h = y2 - y1;
38+
/// <summary>
39+
/// Draws a line between two Vector2 points.
40+
/// </summary>
41+
/// <param name="start">Starting point of the line.</param>
42+
/// <param name="end">Ending point of the line.</param>
43+
/// <param name="color">Color of the line.</param>
44+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
45+
public void DrawLine(Vector2 start, Vector2 end, Color color)
46+
=> graphics.DrawLine((int)start.X, (int)start.Y, (int)end.X, (int)end.Y, color);
7147

72-
if (h == 0)
48+
/// <summary>
49+
/// Draws a line between two points using a modified Bresenham's line algorithm.
50+
/// </summary>
51+
/// <remarks>
52+
/// This implementation minimizes MonoGame Draw calls by drawing line segments.
53+
/// </remarks>
54+
/// <param name="x1">Starting x coordinate.</param>
55+
/// <param name="y1">Starting y coordinate.</param>
56+
/// <param name="x2">Ending x coordinate.</param>
57+
/// <param name="y2">Ending y coordinate.</param>
58+
/// <param name="color">Color of the line.</param>
59+
public void DrawLine(int x1, int y1, int x2, int y2, Color color)
7360
{
74-
graphics.DrawRow(x1, x2, y1, color);
75-
return;
76-
}
61+
var w = x2 - x1;
7762

78-
var dy2 = 0;
79-
var dx1 = w < 0 ? -1 : 1;
80-
var dy1 = h < 0 ? -1 : 1;
81-
var dx2 = w < 0 ? -1 : 1;
82-
var longest = Math.Abs(w);
83-
var shortest = Math.Abs(h);
84-
if (!(longest > shortest))
85-
{
86-
(shortest, longest) = (longest, shortest);
87-
dy2 = h < 0 ? -1 : 1;
88-
dx2 = 0;
89-
}
63+
if (w == 0)
64+
{
65+
graphics.DrawColumn(x1, y1, y2, color);
66+
return;
67+
}
9068

91-
var numerator = longest >> 1;
92-
var oldX = x1;
93-
var oldY = y1;
69+
var h = y2 - y1;
9470

95-
for (var i = 0; i <= longest; i++)
96-
{
97-
numerator += shortest;
98-
if (!(numerator < longest))
71+
if (h == 0)
9972
{
100-
numerator -= longest;
101-
x1 += dx1;
102-
y1 += dy1;
73+
graphics.DrawRow(x1, x2, y1, color);
74+
return;
75+
}
10376

104-
if ((x1 != oldX && y1 != oldY) || i == longest)
105-
{
106-
var rectX = Math.Min(oldX, x1 - dx1);
107-
var rectY = Math.Min(oldY, y1 - dy1);
108-
var rectW = Math.Abs(x1 - dx1 - oldX) + 1;
109-
var rectH = Math.Abs(y1 - dy1 - oldY) + 1;
110-
graphics.DrawFilledRectangle(rectX, rectY, rectW, rectH, color);
111-
oldX = x1;
112-
oldY = y1;
113-
}
77+
var dy2 = 0;
78+
var dx1 = w < 0 ? -1 : 1;
79+
var dy1 = h < 0 ? -1 : 1;
80+
var dx2 = w < 0 ? -1 : 1;
81+
var longest = Math.Abs(w);
82+
var shortest = Math.Abs(h);
83+
if (!(longest > shortest))
84+
{
85+
(shortest, longest) = (longest, shortest);
86+
dy2 = h < 0 ? -1 : 1;
87+
dx2 = 0;
11488
}
115-
else
89+
90+
var numerator = longest >> 1;
91+
var oldX = x1;
92+
var oldY = y1;
93+
94+
for (var i = 0; i <= longest; i++)
11695
{
117-
x1 += dx2;
118-
y1 += dy2;
96+
numerator += shortest;
97+
if (!(numerator < longest))
98+
{
99+
numerator -= longest;
100+
x1 += dx1;
101+
y1 += dy1;
119102

120-
if ((x1 != oldX && y1 != oldY) || i == longest)
103+
if ((x1 != oldX && y1 != oldY) || i == longest)
104+
{
105+
var rectX = Math.Min(oldX, x1 - dx1);
106+
var rectY = Math.Min(oldY, y1 - dy1);
107+
var rectW = Math.Abs(x1 - dx1 - oldX) + 1;
108+
var rectH = Math.Abs(y1 - dy1 - oldY) + 1;
109+
graphics.DrawFilledRectangle(rectX, rectY, rectW, rectH, color);
110+
oldX = x1;
111+
oldY = y1;
112+
}
113+
}
114+
else
121115
{
122-
var rectX = Math.Min(oldX, x1 - dx2);
123-
var rectY = Math.Min(oldY, y1 - dy2);
124-
var rectW = Math.Abs(x1 - dx2 - oldX) + 1;
125-
var rectH = Math.Abs(y1 - dy2 - oldY) + 1;
126-
graphics.DrawFilledRectangle(rectX, rectY, rectW, rectH, color);
127-
oldX = x1;
128-
oldY = y1;
116+
x1 += dx2;
117+
y1 += dy2;
118+
119+
if ((x1 != oldX && y1 != oldY) || i == longest)
120+
{
121+
var rectX = Math.Min(oldX, x1 - dx2);
122+
var rectY = Math.Min(oldY, y1 - dy2);
123+
var rectW = Math.Abs(x1 - dx2 - oldX) + 1;
124+
var rectH = Math.Abs(y1 - dy2 - oldY) + 1;
125+
graphics.DrawFilledRectangle(rectX, rectY, rectW, rectH, color);
126+
oldX = x1;
127+
oldY = y1;
128+
}
129129
}
130130
}
131131
}

0 commit comments

Comments
 (0)