public void SetAxis(AxisModel axis) { Config = new CanvasConfiguration(); Config.BuildConfiguration(axis, AttachedCanvas.ActualWidth, AttachedCanvas.ActualHeight); DrawGrid(); AdjustLocationsAfterResize(); }
//public static // Layer 0: Grid points / axis // Layer 1: Input Layer // Layer 2: Input Annotation Layer // Layer 3: Algorithm Layer // Layer 4: Algorithm Annotation Layer public CanvasWrapper(Canvas c, CanvasConfiguration config = null) { AttachedCanvas = c; Layers = new List <CanvasLayer>(); CreateNewLayer("Base Grid Layer"); ActiveLayer = Layers[0]; CreateNewLayer("Input Layer"); CreateNewLayer("Input Annotation Layer"); CreateNewLayer("Algorithm Layer"); CreateNewLayer("Algorithm Annotation Layer"); //Config = new CanvasConfiguration(); Config = config; //Config.BuildConfiguration(-200, 200, -100, 100, // AttachedCanvas.ActualWidth, AttachedCanvas.ActualHeight, // 40, 20, 5, 5); InputPoints = new List <Vector>(); InputLines = new List <LineModel>(); InputPolygons = new List <PolygonModel>(); ActivePolygon = null; DrawGrid(); HookEvents(); CreateDefaultShapes(); }
private void DrawGrid() { if (dotGrid == null) { dotGrid = new CanvasComponent(); } if (Config == null) { // If we don't have a configuration yet, create the default... Config = new CanvasConfiguration(); Config.BuildConfiguration(-800, 800, -400, 400, AttachedCanvas.ActualWidth, AttachedCanvas.ActualHeight, 40, 20, 5, 5); } ResetGrid(); double total_x = Math.Abs(Config.XMin) + Config.XMax; double total_y = Math.Abs(Config.YMin) + Config.YMax; double pct_x = Math.Abs(Config.XMin) / total_x; double pct_y = Math.Abs(Config.YMax) / total_y; int origin_xi = (int)(pct_x * (double)Config.XCount); int origin_yi = (int)(pct_y * (double)Config.YCount); double origin_xp = origin_xi * Config.XIncrement + Config.XStart + 1; double origin_yp = origin_yi * Config.YIncrement + Config.YStart + 1; var axisLine = CreateLine(0, origin_yp, AttachedCanvas.ActualWidth, origin_yp); axisLine.Stroke = new SolidColorBrush(Colors.Black); if (axisLineX != null) { GetBaseLayer().RemoveComponent(axisLineX); axisLineX.Shapes.Clear(); } else { axisLineX = new CanvasComponent(); } axisLineX.AddUiElement(axisLine); GetBaseLayer().AddComponent(axisLineX); axisLine = CreateLine(origin_xp, 0, origin_xp, AttachedCanvas.ActualHeight); axisLine.Stroke = new SolidColorBrush(Colors.Black); if (axisLineY != null) { GetBaseLayer().RemoveComponent(axisLineY); axisLineY.Shapes.Clear(); } else { axisLineY = new CanvasComponent(); } axisLineY.AddUiElement(axisLine); GetBaseLayer().AddComponent(axisLineY); }
public static CanvasPoint TranslateFromValues(CanvasConfiguration c, double x, double y) { var p = new CanvasPoint(); p.ValueX = x; p.ValueY = y; p.DotIndexLeft = (int)((p.ValueX - c.XMin) / c.ValueTickX); p.DotIndexTop = (int)((p.ValueY - c.YMin) / c.ValueTickY); p.DotIndexTop = -(p.DotIndexTop - c.YCount); return(p); }
public static CanvasPoint TranslateFromMouse(CanvasConfiguration c, double xp, double yp) { var p = new CanvasPoint(); p.Config = c; p.DotLeft = xp; p.DotTop = yp; p.DotIndexLeft = (int)((xp - c.XStart + c.XIncrement / 2) / c.XIncrement); p.DotIndexTop = (int)((yp - c.YStart + c.YIncrement / 2) / c.YIncrement); p.ValueX = c.ValueTickX * p.DotIndexLeft + c.XMin; p.ValueY = c.ValueTickY * (c.YCount - p.DotIndexTop) + c.YMin; return(p); }
public void SetConfiguration(CanvasConfiguration c) { Config = c; }