Skip to content
Snippets Groups Projects
Commit cbea6938 authored by Paul-Winpenny's avatar Paul-Winpenny
Browse files

Nodes are now in correct places for desktop.

parent 402e46b0
No related branches found
No related tags found
No related merge requests found
......@@ -69,31 +69,66 @@ namespace RobobinApp.Views
private void DrawNodes(ICanvas canvas, float nodeRadius, Node highlightedNode)
{
// Calculate offsets to center the nodes
float canvasCenterX = storedDirtyRect.Width * 4.5f / 7;
float canvasCenterY = storedDirtyRect.Height / 2;
// Calculate the center of the graph based on node coordinates
float graphCenterX = (_graph.Nodes.Min(node => node.X) + _graph.Nodes.Max(node => node.X)) / 2;
float graphCenterY = (_graph.Nodes.Min(node => node.Y) + _graph.Nodes.Max(node => node.Y)) / 2;
// Offset to center the graph
float offsetX = canvasCenterX - graphCenterX;
float offsetY = canvasCenterY - graphCenterY;
foreach (var node in _graph.Nodes)
{
float x = node.X; // Use the original X-coordinate
float y = node.Y; // Use the original Y-coordinate
// Apply centering offsets
float centeredX = node.X + offsetX;
float centeredY = node.Y + offsetY;
// Set fill color based on whether the node is highlighted
canvas.FillColor = (highlightedNode == node) ? HighlightedNodeColor : DefaultNodeColor;
// Draw the node as a circle
canvas.FillCircle(x, y, nodeRadius);
canvas.FillCircle(centeredX, centeredY, nodeRadius);
// Optionally, draw node name or other details
canvas.FontColor = Colors.White;
canvas.DrawString(node.Name, x + nodeRadius + 2, y - nodeRadius, HorizontalAlignment.Left);
canvas.FontColor = Colors.Black;
canvas.DrawString(node.Name, centeredX + nodeRadius + 2, centeredY - nodeRadius, HorizontalAlignment.Left);
}
}
public Node FindNearestNode(float tapPointX, float tapPointY)
{
// Calculate offsets to center the nodes
float canvasCenterX = storedDirtyRect.Width * 4.5f / 7;
float canvasCenterY = storedDirtyRect.Height / 2;
// Calculate the center of the graph based on node coordinates
float graphCenterX = (_graph.Nodes.Min(node => node.X) + _graph.Nodes.Max(node => node.X)) / 2;
float graphCenterY = (_graph.Nodes.Min(node => node.Y) + _graph.Nodes.Max(node => node.Y)) / 2;
// Offset to center the graph
float offsetX = canvasCenterX - graphCenterX;
float offsetY = canvasCenterY - graphCenterY;
float minDistance = float.MaxValue;
Node nearestNode = null;
foreach (var node in _graph.Nodes)
{
float distance = (float)Math.Sqrt(Math.Pow(node.X - tapPointX, 2) + Math.Pow(node.Y - tapPointY, 2));
// Apply centering offsets to node positions
float centeredX = node.X + offsetX;
float centeredY = node.Y + offsetY;
// Calculate the distance between the tapped point and the centered node position
float distance = (float)Math.Sqrt(
Math.Pow(centeredX - tapPointX, 2) +
Math.Pow(centeredY - tapPointY, 2)
);
if (distance < minDistance)
{
minDistance = distance;
......@@ -103,5 +138,6 @@ namespace RobobinApp.Views
return nearestNode;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment