Skip to content

Commit

Permalink
Add context menu for positioning points
Browse files Browse the repository at this point in the history
Also hopefully fix delete buttons on high DPI displays.
  • Loading branch information
burninrubber0 committed Jul 13, 2023
1 parent a65c977 commit 7e01012
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 28 deletions.
2 changes: 1 addition & 1 deletion PVSFormat/PVSEditControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected enum MapSectionType
Neighbour
}

protected PointF MousePosOnMap
internal PointF MousePosOnMap
{
get
{
Expand Down
21 changes: 11 additions & 10 deletions PVSFormat/PVSEditor.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 56 additions & 17 deletions PVSFormat/PVSEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private void PVSEditor_FormClosing(object sender, FormClosingEventArgs e)
Edit?.Invoke();
}

private void pvsMain_DoubleClick(object sender, System.EventArgs e)
private void pvsMain_DoubleClick(object sender, EventArgs e)
{
ulong zoneId = pvsMain.GetZoneId();
if (zoneId == ulong.MaxValue)
Expand All @@ -111,7 +111,46 @@ private void pvsMain_DoubleClick(object sender, System.EventArgs e)
zonesListBox.SelectedIndex = zonesListBox.FindStringExact(zoneId.ToString("000"));
}

private void zonesListBox_SelectedIndexChanged(object sender, System.EventArgs e)
private void pvsMain_Click(object sender, EventArgs e)
{
if (((MouseEventArgs)e).Button == MouseButtons.Right
&& pvsMain.PVS.selectedZoneId != ulong.MaxValue)
OpenContextMenu();
}

private void OpenContextMenu()
{
ContextMenuStrip menu = new();
for (int i = 0; i < 4; ++i)
menu.Items.Add("Use as point " + (i + 1).ToString());
menu.Items[0].Click += (s, e) =>
{
Vector2 pos = pvsMain.MousePosOnMap.ToVector2();
point1XNumericUpDown.Value = (decimal)pos.X;
point1YNumericUpDown.Value = (decimal)pos.Y;
};
menu.Items[1].Click += (s, e) =>
{
Vector2 pos = pvsMain.MousePosOnMap.ToVector2();
point2XNumericUpDown.Value = (decimal)pos.X;
point2YNumericUpDown.Value = (decimal)pos.Y;
};
menu.Items[2].Click += (s, e) =>
{
Vector2 pos = pvsMain.MousePosOnMap.ToVector2();
point3XNumericUpDown.Value = (decimal)pos.X;
point3YNumericUpDown.Value = (decimal)pos.Y;
};
menu.Items[3].Click += (s, e) =>
{
Vector2 pos = pvsMain.MousePosOnMap.ToVector2();
point4XNumericUpDown.Value = (decimal)pos.X;
point4YNumericUpDown.Value = (decimal)pos.Y;
};
menu.Show(Cursor.Position);
}

private void zonesListBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (zonesListBox.SelectedIndex == -1)
return;
Expand All @@ -121,7 +160,7 @@ private void zonesListBox_SelectedIndexChanged(object sender, System.EventArgs e
deleteZoneButton.Enabled = true;
}

private void addZoneButton_Click(object sender, System.EventArgs e)
private void addZoneButton_Click(object sender, EventArgs e)
{
var zones = GetZones();
ulong newZoneId;
Expand Down Expand Up @@ -149,7 +188,7 @@ private void addZoneButton_Click(object sender, System.EventArgs e)
deleteZoneButton.Enabled = true;
}

private void deleteZoneButton_Click(object sender, System.EventArgs e)
private void deleteZoneButton_Click(object sender, EventArgs e)
{
int index = zonesListBox.SelectedIndex;
ulong zoneId = ulong.Parse(zonesListBox.Items[index].ToString());
Expand All @@ -168,71 +207,71 @@ private void deleteZoneButton_Click(object sender, System.EventArgs e)
zonesListBox.SelectedIndex = index;
}

private void point1XNumericUpDown_ValueChanged(object sender, System.EventArgs e)
private void point1XNumericUpDown_ValueChanged(object sender, EventArgs e)
{
Vector2 point = GetPoints()[0];
point.X = (float)point1XNumericUpDown.Value;
GetPoints()[0] = point;
pvsMain.Invalidate();
}

private void point1YNumericUpDown_ValueChanged(object sender, System.EventArgs e)
private void point1YNumericUpDown_ValueChanged(object sender, EventArgs e)
{
Vector2 point = GetPoints()[0];
point.Y = (float)point1YNumericUpDown.Value;
GetPoints()[0] = point;
pvsMain.Invalidate();
}

private void point2XNumericUpDown_ValueChanged(object sender, System.EventArgs e)
private void point2XNumericUpDown_ValueChanged(object sender, EventArgs e)
{
Vector2 point = GetPoints()[1];
point.X = (float)point2XNumericUpDown.Value;
GetPoints()[1] = point;
pvsMain.Invalidate();
}

private void point2YNumericUpDown_ValueChanged(object sender, System.EventArgs e)
private void point2YNumericUpDown_ValueChanged(object sender, EventArgs e)
{
Vector2 point = GetPoints()[1];
point.Y = (float)point2YNumericUpDown.Value;
GetPoints()[1] = point;
pvsMain.Invalidate();
}

private void point3XNumericUpDown_ValueChanged(object sender, System.EventArgs e)
private void point3XNumericUpDown_ValueChanged(object sender, EventArgs e)
{
Vector2 point = GetPoints()[2];
point.X = (float)point3XNumericUpDown.Value;
GetPoints()[2] = point;
pvsMain.Invalidate();
}

private void point3YNumericUpDown_ValueChanged(object sender, System.EventArgs e)
private void point3YNumericUpDown_ValueChanged(object sender, EventArgs e)
{
Vector2 point = GetPoints()[2];
point.Y = (float)point3YNumericUpDown.Value;
GetPoints()[2] = point;
pvsMain.Invalidate();
}

private void point4XNumericUpDown_ValueChanged(object sender, System.EventArgs e)
private void point4XNumericUpDown_ValueChanged(object sender, EventArgs e)
{
Vector2 point = GetPoints()[3];
point.X = (float)point4XNumericUpDown.Value;
GetPoints()[3] = point;
pvsMain.Invalidate();
}

private void point4YNumericUpDown_ValueChanged(object sender, System.EventArgs e)
private void point4YNumericUpDown_ValueChanged(object sender, EventArgs e)
{
Vector2 point = GetPoints()[3];
point.Y = (float)point4YNumericUpDown.Value;
GetPoints()[3] = point;
pvsMain.Invalidate();
}

private void neighboursListBox_SelectedIndexChanged(object sender, System.EventArgs e)
private void neighboursListBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (neighboursListBox.SelectedIndex == -1)
return;
Expand All @@ -247,7 +286,7 @@ private void neighboursListBox_SelectedIndexChanged(object sender, System.EventA
immediateCheckBox.Enabled = true;
}

private void addNeighbourButton_Click(object sender, System.EventArgs e)
private void addNeighbourButton_Click(object sender, EventArgs e)
{
ulong newZoneId = new AddZone().GetNewZoneId();
if (newZoneId == ulong.MaxValue)
Expand All @@ -268,7 +307,7 @@ private void addNeighbourButton_Click(object sender, System.EventArgs e)
deleteNeighbourButton.Enabled = true;
}

private void deleteNeighbourButton_Click(object sender, System.EventArgs e)
private void deleteNeighbourButton_Click(object sender, EventArgs e)
{
int index = neighboursListBox.SelectedIndex;
ulong zoneId = ulong.Parse(neighboursListBox.Items[index].ToString());
Expand All @@ -295,7 +334,7 @@ private void deleteNeighbourButton_Click(object sender, System.EventArgs e)
neighboursListBox.SelectedIndex = index;
}

private void renderCheckBox_CheckedChanged(object sender, System.EventArgs e)
private void renderCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (neighboursListBox.SelectedIndex == -1)
return;
Expand All @@ -308,7 +347,7 @@ private void renderCheckBox_CheckedChanged(object sender, System.EventArgs e)
GetUnsafeNeighbours()[neighbourIndex] = neighbour;
}

private void immediateCheckBox_CheckedChanged(object sender, System.EventArgs e)
private void immediateCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (neighboursListBox.SelectedIndex == -1)
return;
Expand Down

0 comments on commit 7e01012

Please sign in to comment.