Skip to content

Commit 89f36ef

Browse files
committed
Adding rotation capabilities
1 parent 8feaf54 commit 89f36ef

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed

FidgetSpinnerEditor/FormMain.Designer.cs

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FidgetSpinnerEditor/FormMain.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public partial class FormMain : Form
1616
private PointF _center;
1717
private Rectangle _drawingArea;
1818
private RectangleF _innerDrawingArea;
19-
private int _ledSize;
19+
private int _ledSize, _rotation = 0;
20+
private double LedAngleBetweenColumns = 360 / LedColumns;
2021

2122
public FormMain()
2223
{
@@ -46,12 +47,15 @@ private void pictureBoxEditor_Paint(object sender, PaintEventArgs e)
4647
for (var i = 0; i < LedRows; i++)
4748
{
4849
var p = new PointF(_center.X,_drawingArea.Top + (yspacing * (1 + i)));
50+
var r = _rotation;
4951

5052
for (var j = 0; j < LedColumns; j++)
5153
{
54+
p = RotatePoint(p, _center, r+ LedAngleBetweenColumns);
55+
r = 0;
56+
5257
e.Graphics.FillEllipse(GetBit(i + j * LedRows) ? Brushes.Blue : Brushes.LightYellow,
5358
p.X - _ledSize / 2, p.Y - _ledSize / 2, _ledSize, _ledSize);
54-
p = RotatePoint(p, _center, 360 / LedColumns);
5559
}
5660
}
5761
}
@@ -179,6 +183,18 @@ public static byte[] BitArrayToByteArray(BitArray bits)
179183
return output.ToArray();
180184
}
181185

186+
private void counterclockwiseToolStripMenuItem_Click(object sender, EventArgs e)
187+
{
188+
_rotation -= 5;
189+
pictureBoxEditor.Invalidate();
190+
}
191+
192+
private void clockwiseToolStripMenuItem_Click(object sender, EventArgs e)
193+
{
194+
_rotation += 5;
195+
pictureBoxEditor.Invalidate();
196+
}
197+
182198
private int GetBitByPosition(Point point)
183199
{
184200
if (!_drawingArea.IsEmpty && !_innerDrawingArea.IsEmpty && !_center.IsEmpty)
@@ -187,12 +203,15 @@ private int GetBitByPosition(Point point)
187203
for (var i = 0; i < LedRows; i++)
188204
{
189205
var p = new PointF(_center.X, _drawingArea.Top + (yspacing * (1 + i)));
206+
var r = _rotation;
190207

191208
for (var j = 0; j < LedColumns; j++)
192209
{
210+
p = RotatePoint(p, _center, r + LedAngleBetweenColumns);
211+
r = 0;
212+
193213
if (new RectangleF(p.X - _ledSize / 2, p.Y - _ledSize / 2, _ledSize, _ledSize).Contains(point))
194214
return i + j * LedRows;
195-
p = RotatePoint(p, _center, 360 / LedColumns);
196215
}
197216
}
198217
}

FidgetSpinnerEditor/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("0.1.0.0")]
36-
[assembly: AssemblyFileVersion("0.1.0.0")]
35+
[assembly: AssemblyVersion("0.2.0.0")]
36+
[assembly: AssemblyFileVersion("0.2.0.0")]

0 commit comments

Comments
 (0)