private void CheckForOpenCurve3() { if (curve3Control.X != double.MinValue) { // we started this polygon with a control point so add the required curve3 var vertex = vertexStorage.vertex(polygonStartIndex, out var x, out var y); vertexStorage.curve3(curve3Control.X, curve3Control.Y, x, y); // reset the curve3Control point to unitialized curve3Control = new Vector2(double.MinValue, double.MinValue); } }
private static IVertexSource BuildShape(RectangleDouble rect, double topLeftRadius, double topRightRadius, double bottomRightRadius, double bottomLeftRadius) { // See https://photos.app.goo.gl/YdTiehf6ih7fSoDA9 for point diagram var centerY = rect.YCenter; double radius; var tabShape2 = new VertexStorage(); // A -> B radius = bottomLeftRadius; tabShape2.MoveTo(rect.Left + radius, rect.Bottom); if (radius > 0) { tabShape2.curve3(rect.Left, rect.Bottom, rect.Left, rect.Bottom + radius); } // C -> D radius = topLeftRadius; tabShape2.LineTo(rect.Left, rect.Top - radius); if (radius > 0) { tabShape2.curve3(rect.Left, rect.Top, rect.Left + radius, rect.Top); } // E -> F radius = topRightRadius; tabShape2.LineTo(rect.Right - radius, rect.Top); if (radius > 0) { tabShape2.curve3(rect.Right, rect.Top, rect.Right, rect.Top - radius); } // G -> H radius = bottomRightRadius; tabShape2.LineTo(rect.Right, rect.Bottom + radius); if (radius > 0) { tabShape2.curve3(rect.Right, rect.Bottom, rect.Right - radius, rect.Bottom); } // H -> A radius = bottomLeftRadius; tabShape2.LineTo(rect.Left - radius, rect.Bottom); return(new FlattenCurves(tabShape2)); }
public override void OnBoundsChanged(EventArgs e) { base.OnBoundsChanged(e); var rect = this.LocalBounds; var centerY = rect.YCenter; // Tab - core var radius = 3.0; var tabShape2 = new VertexStorage(); tabShape2.MoveTo(rect.Left + radius, rect.Bottom); tabShape2.curve3(rect.Left, rect.Bottom, rect.Left, rect.Bottom + radius); tabShape2.LineTo(rect.Left, rect.Top - radius); tabShape2.curve3(rect.Left, rect.Top, rect.Left + radius, rect.Top); tabShape2.LineTo(rect.Right - 8, rect.Top); tabShape2.LineTo(rect.Right, centerY); tabShape2.LineTo(rect.Right - 8, rect.Bottom); tabShape2.LineTo(rect.Left, rect.Bottom); tabShape = new FlattenCurves(tabShape2); }
public GuiWidget NewEditWidget(ThemeConfig theme) { var histogramWidget = new GuiWidget() { HAnchor = HAnchor.Stretch, Height = 60 * GuiWidget.DeviceScale, Margin = 5, }; var handleWidth = 10; var handleDeviceWidth = handleWidth * GuiWidget.DeviceScale; var histogramBackground = new GuiWidget() { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Stretch, Margin = new BorderDouble(handleWidth, 0) }; histogramBackground.AfterDraw += (s, e) => { var rangeStart = RangeStart; var rangeEnd = RangeEnd; var graphics2D = e.Graphics2D; graphics2D.Render(_histogramRawCache, 0, 0, histogramBackground.Width, histogramBackground.Height); graphics2D.FillRectangle(rangeStart * histogramBackground.Width, 0, rangeEnd * histogramBackground.Width, histogramBackground.Height, theme.PrimaryAccentColor.WithAlpha(60)); }; histogramWidget.AddChild(histogramBackground); void RenderHandle(Graphics2D g, double s, double e) { var w = g.Width; var h = g.Height; g.Line(w * e, 0, w * e, h, theme.TextColor); var leftEdge = new VertexStorage(); leftEdge.MoveTo(w * e, h * .80); leftEdge.curve3(w * e, h * .70, w * .5, h * .70); leftEdge.curve3(w * s, h * .60); leftEdge.LineTo(w * s, h * .40); leftEdge.curve3(w * s, h * .30, w * .5, h * .30); leftEdge.curve3(w * e, h * .20); g.Render(new FlattenCurves(leftEdge), theme.PrimaryAccentColor); g.Line(w * .35, h * .6, w * .35, h * .4, theme.BackgroundColor); g.Line(w * .65, h * .6, w * .65, h * .4, theme.BackgroundColor); } var leftHandle = new ImageWidget((int)(handleDeviceWidth), (int)histogramWidget.Height); leftHandle.Position = new Vector2(RangeStart * histogramBackground.Width, 0); var image = leftHandle.Image; RenderHandle(image.NewGraphics2D(), 0, 1); histogramWidget.AddChild(leftHandle); bool leftDown = false; var leftX = 0.0; leftHandle.MouseDown += (s, e) => { if (e.Button == MouseButtons.Left) { leftDown = true; leftX = e.Position.X; } }; leftHandle.MouseMove += (s, e) => { if (leftDown) { var offset = e.Position.X - leftX; var newStart = RangeStart + offset / histogramBackground.Width; newStart = agg_basics.Clamp(newStart, 0, RangeEnd); if (RangeStart != newStart) { RangeStart = newStart; leftHandle.Position = new Vector2(RangeStart * histogramBackground.Width, 0); RangeChanged?.Invoke(this, null); } } }; leftHandle.MouseUp += (s, e) => { if (leftDown) { leftDown = false; EditComplete?.Invoke(this, null); } }; var rightHandle = new ImageWidget((int)(handleDeviceWidth), (int)histogramWidget.Height); rightHandle.Position = new Vector2(RangeEnd * histogramBackground.Width + handleDeviceWidth, 0); image = rightHandle.Image; RenderHandle(image.NewGraphics2D(), 1, 0); histogramWidget.AddChild(rightHandle); bool rightDown = false; var rightX = 0.0; rightHandle.MouseDown += (s, e) => { if (e.Button == MouseButtons.Left) { rightDown = true; rightX = e.Position.X; } }; rightHandle.MouseMove += (s, e) => { if (rightDown) { var offset = e.Position.X - rightX; var newEnd = RangeEnd + offset / histogramBackground.Width; newEnd = agg_basics.Clamp(newEnd, RangeStart, 1); if (RangeEnd != newEnd) { RangeEnd = newEnd; rightHandle.Position = new Vector2(RangeEnd * histogramBackground.Width + handleDeviceWidth, 0); RangeChanged?.Invoke(this, null); } } }; rightHandle.MouseUp += (s, e) => { if (rightDown) { rightDown = false; EditComplete?.Invoke(this, null); } }; // grabing the center bool centerDown = false; var centerX = 0.0; var downStart = 0.0; var downEnd = 0.0; histogramBackground.MouseDown += (s, e) => { if (e.Button == MouseButtons.Left) { centerDown = true; centerX = e.Position.X; downStart = RangeStart; downEnd = RangeEnd; } }; histogramBackground.MouseMove += (s, e) => { if (centerDown) { var newStart = RangeStart; var newEnd = RangeEnd; var offset = e.Position.X - centerX; if (offset < 0) { newStart = Math.Max(downStart + offset / histogramBackground.Width, 0); newEnd = newStart + (downEnd - downStart); } else { newEnd = Math.Min(downEnd + offset / histogramBackground.Width, 1); newStart = newEnd - (downEnd - downStart); } if (RangeStart != newStart && RangeEnd != newEnd) { RangeStart = newStart; RangeEnd = newEnd; leftHandle.Position = new Vector2(RangeStart * histogramBackground.Width, 0); rightHandle.Position = new Vector2(RangeEnd * histogramBackground.Width + handleDeviceWidth, 0); RangeChanged?.Invoke(this, null); histogramBackground.Invalidate(); } } }; histogramBackground.MouseUp += (s, e) => { if (centerDown) { centerDown = false; EditComplete?.Invoke(this, null); } }; histogramBackground.BoundsChanged += (s, e) => { leftHandle.Position = new Vector2(RangeStart * histogramBackground.Width, 0); rightHandle.Position = new Vector2(RangeEnd * histogramBackground.Width + handleDeviceWidth, 0); }; return(histogramWidget); }
public CalibrationTabWidget(XyCalibrationWizard calibrationWizard, TextButton nextButton, ThemeConfig theme) { this.calibrationWizard = calibrationWizard; this.theme = theme; this.NextButton = nextButton; tabBaseColor = new Color(theme.SlightShade.ToColorF(), theme.SlightShade.Alpha0To1 * 1.2); double barWidth = 30; double barHeight = 300; double left = LocalBounds.Left + 15; double bottom = LocalBounds.Bottom + 15; double right = left + barHeight; var a = new Vector2(left, bottom); var b = new Vector2(left, bottom + barHeight); var c = new Vector2(left + barWidth, bottom + barHeight); var d = new Vector2(left + barWidth, bottom + barWidth); var e = new Vector2(right, bottom + barWidth); var f = new Vector2(right + (barWidth * .7), bottom + (barWidth / 2)); var g = new Vector2(right, bottom); var m = new Vector2(b.X + (barWidth / 2), b.Y + (barWidth * .6)); var n = new Vector2(m.X, b.Y); var r = new Vector2(b.X, m.Y); var tabShape2 = new VertexStorage(); tabShape2.Add(a.X, a.Y, FlagsAndCommand.MoveTo); // A tabShape2.LineTo(b); // A - B tabShape2.curve3(r.X, r.Y, m.X, m.Y); // B -> C tabShape2.curve3(c.X, c.Y); tabShape2.LineTo(d); // C -> D tabShape2.LineTo(e); // D -> E tabShape2.LineTo(f); // E -> F tabShape2.LineTo(g); // F -> G tabShape2.ClosePolygon(); int highlightStroke = 2; int highlightOffset = 8; int highlightWidth = 16; double x1 = d.X + highlightOffset; double x2 = x1 + highlightWidth; double y1 = d.Y + highlightOffset; double y2 = c.Y - highlightOffset; double midY = y1 + (y2 - y1) / 2; var highlighter = new VertexStorage(); highlighter.MoveTo(x1, y1); highlighter.LineTo(x2, y1); highlighter.LineTo(x2, midY); highlighter.LineTo(x2 + highlightOffset, midY); highlighter.LineTo(x2, midY); highlighter.LineTo(x2, y2); highlighter.LineTo(x1, y2); xHighlighter = new Stroke(highlighter, highlightStroke); xLabel = new TextWidget("Select the most centered pad", pointSize: theme.DefaultFontSize, textColor: theme.TextColor) { HAnchor = HAnchor.Absolute, VAnchor = VAnchor.Absolute }; xLabel.Position = new Vector2(x2 + highlightOffset * 2, midY - xLabel.Height / 2); this.AddChild(xLabel); x1 = d.X + highlightOffset; y1 = d.Y + 50; x1 = d.X + highlightOffset; x2 = e.X - highlightOffset; y1 = d.Y + highlightOffset; y2 = y1 + highlightWidth; double midX = x1 + (x2 - x1) / 2; highlighter = new VertexStorage(); highlighter.MoveTo(x1, y1); highlighter.LineTo(x1, y2); highlighter.LineTo(midX, y2); highlighter.LineTo(midX, y2 + highlightOffset); highlighter.LineTo(midX, y2); highlighter.LineTo(x2, y2); highlighter.LineTo(x2, y1); yHighlighter = new Stroke(highlighter, highlightStroke); yLabel = new TextWidget("Select the most centered pad", pointSize: theme.DefaultFontSize, textColor: theme.TextColor) { HAnchor = HAnchor.Absolute, VAnchor = VAnchor.Absolute, Visible = false, }; this.AddChild(yLabel); yLabel.Position = new Vector2(midX - yLabel.Width / 2, y2 + (highlightOffset * 2)); yHighlighter = new Stroke(highlighter, highlightStroke); int padCount = 7; double cellSize = (barHeight - barWidth) / padCount; int padding = (int)(cellSize * .3); double padSize = cellSize - padding; var titles = new[] { "-3", "-2", "-1", "0", "+1", "+2", "+3" }; for (var i = 0; i < padCount; i++) { this.AddChild(new CalibrationPad(titles[i], theme, pointSize: theme.DefaultFontSize - 1) { Position = new Vector2(left, bottom + 3 + barWidth + (cellSize * i)), Height = padSize, Width = barWidth, Index = i, IsActive = i == 3, Axis = PrinterConnection.Axis.X }); this.AddChild(new CalibrationPad(titles[i], theme, pointSize: theme.DefaultFontSize - 1) { Position = new Vector2(left + 3 + barWidth + (cellSize * i), bottom), Height = barWidth, Width = padSize, Index = i, IsActive = i == 3, Axis = PrinterConnection.Axis.Y }); } foreach (var calibrationPad in this.Children.OfType <CalibrationPad>()) { calibrationPad.Click += this.CalibrationPad_Click; calibrationPad.Hovered += this.CalibrationPad_Hovered; } tabShape = new FlattenCurves(tabShape2); tabStroke = new Stroke(tabShape); }
private void render_gpc(Graphics2D graphics2D) { switch (m_polygons.SelectedIndex) { case 0: { //------------------------------------ // Two simple paths // VertexStorage ps1 = new VertexStorage(); VertexStorage ps2 = new VertexStorage(); double x = m_x - Width / 2 + 100; double y = m_y - Height / 2 + 100; ps1.MoveTo(x + 140, y + 145); ps1.LineTo(x + 225, y + 44); ps1.LineTo(x + 296, y + 219); ps1.ClosePolygon(); ps1.LineTo(x + 226, y + 289); ps1.LineTo(x + 82, y + 292); ps1.MoveTo(x + 220, y + 222); ps1.LineTo(x + 363, y + 249); ps1.LineTo(x + 265, y + 331); ps1.MoveTo(x + 242, y + 243); ps1.LineTo(x + 268, y + 309); ps1.LineTo(x + 325, y + 261); ps1.MoveTo(x + 259, y + 259); ps1.LineTo(x + 273, y + 288); ps1.LineTo(x + 298, y + 266); ps2.MoveTo(100 + 32, 100 + 77); ps2.LineTo(100 + 473, 100 + 263); ps2.LineTo(100 + 351, 100 + 290); ps2.LineTo(100 + 354, 100 + 374); graphics2D.Render(ps1, new ColorF(0, 0, 0, 0.1).ToColor()); graphics2D.Render(ps2, new ColorF(0, 0.6, 0, 0.1).ToColor()); CreateAndRenderCombined(graphics2D, ps1, ps2); } break; case 1: { //------------------------------------ // Closed stroke // VertexStorage ps1 = new VertexStorage(); VertexStorage ps2 = new VertexStorage(); Stroke stroke = new Stroke(ps2); stroke.width(10.0); double x = m_x - Width / 2 + 100; double y = m_y - Height / 2 + 100; ps1.MoveTo(x + 140, y + 145); ps1.LineTo(x + 225, y + 44); ps1.LineTo(x + 296, y + 219); ps1.ClosePolygon(); ps1.LineTo(x + 226, y + 289); ps1.LineTo(x + 82, y + 292); ps1.MoveTo(x + 220 - 50, y + 222); ps1.LineTo(x + 265 - 50, y + 331); ps1.LineTo(x + 363 - 50, y + 249); ps1.close_polygon(ShapePath.FlagsAndCommand.FlagCCW); ps2.MoveTo(100 + 32, 100 + 77); ps2.LineTo(100 + 473, 100 + 263); ps2.LineTo(100 + 351, 100 + 290); ps2.LineTo(100 + 354, 100 + 374); ps2.ClosePolygon(); graphics2D.Render(ps1, new ColorF(0, 0, 0, 0.1).ToColor()); graphics2D.Render(stroke, new ColorF(0, 0.6, 0, 0.1).ToColor()); CreateAndRenderCombined(graphics2D, ps1, stroke); } break; case 2: { //------------------------------------ // Great Britain and Arrows // VertexStorage gb_poly = new VertexStorage(); VertexStorage arrows = new VertexStorage(); GreatBritanPathStorage.Make(gb_poly); make_arrows(arrows); Affine mtx1 = Affine.NewIdentity(); Affine mtx2 = Affine.NewIdentity(); mtx1 *= Affine.NewTranslation(-1150, -1150); mtx1 *= Affine.NewScaling(2.0); mtx2 = mtx1; mtx2 *= Affine.NewTranslation(m_x - Width / 2, m_y - Height / 2); VertexSourceApplyTransform trans_gb_poly = new VertexSourceApplyTransform(gb_poly, mtx1); VertexSourceApplyTransform trans_arrows = new VertexSourceApplyTransform(arrows, mtx2); graphics2D.Render(trans_gb_poly, new ColorF(0.5, 0.5, 0, 0.1).ToColor()); Stroke stroke_gb_poly = new Stroke(trans_gb_poly); stroke_gb_poly.Width = 0.1; graphics2D.Render(stroke_gb_poly, new ColorF(0, 0, 0).ToColor()); graphics2D.Render(trans_arrows, new ColorF(0.0, 0.5, 0.5, 0.1).ToColor()); CreateAndRenderCombined(graphics2D, trans_gb_poly, trans_arrows); } break; case 3: { //------------------------------------ // Great Britain and a Spiral // spiral sp = new spiral(m_x, m_y, 10, 150, 30, 0.0); Stroke stroke = new Stroke(sp); stroke.width(15.0); VertexStorage gb_poly = new VertexStorage(); GreatBritanPathStorage.Make(gb_poly); Affine mtx = Affine.NewIdentity();; mtx *= Affine.NewTranslation(-1150, -1150); mtx *= Affine.NewScaling(2.0); VertexSourceApplyTransform trans_gb_poly = new VertexSourceApplyTransform(gb_poly, mtx); graphics2D.Render(trans_gb_poly, new ColorF(0.5, 0.5, 0, 0.1).ToColor()); Stroke stroke_gb_poly = new Stroke(trans_gb_poly); stroke_gb_poly.width(0.1); graphics2D.Render(stroke_gb_poly, new ColorF(0, 0, 0).ToColor()); graphics2D.Render(stroke, new ColorF(0.0, 0.5, 0.5, 0.1).ToColor()); CreateAndRenderCombined(graphics2D, trans_gb_poly, stroke); } break; case 4: { //------------------------------------ // Spiral and glyph // spiral sp = new spiral(m_x, m_y, 10, 150, 30, 0.0); Stroke stroke = new Stroke(sp); stroke.width(15.0); VertexStorage glyph = new VertexStorage(); glyph.MoveTo(28.47, 6.45); glyph.curve3(21.58, 1.12, 19.82, 0.29); glyph.curve3(17.19, -0.93, 14.21, -0.93); glyph.curve3(9.57, -0.93, 6.57, 2.25); glyph.curve3(3.56, 5.42, 3.56, 10.60); glyph.curve3(3.56, 13.87, 5.03, 16.26); glyph.curve3(7.03, 19.58, 11.99, 22.51); glyph.curve3(16.94, 25.44, 28.47, 29.64); glyph.LineTo(28.47, 31.40); glyph.curve3(28.47, 38.09, 26.34, 40.58); glyph.curve3(24.22, 43.07, 20.17, 43.07); glyph.curve3(17.09, 43.07, 15.28, 41.41); glyph.curve3(13.43, 39.75, 13.43, 37.60); glyph.LineTo(13.53, 34.77); glyph.curve3(13.53, 32.52, 12.38, 31.30); glyph.curve3(11.23, 30.08, 9.38, 30.08); glyph.curve3(7.57, 30.08, 6.42, 31.35); glyph.curve3(5.27, 32.62, 5.27, 34.81); glyph.curve3(5.27, 39.01, 9.57, 42.53); glyph.curve3(13.87, 46.04, 21.63, 46.04); glyph.curve3(27.59, 46.04, 31.40, 44.04); glyph.curve3(34.28, 42.53, 35.64, 39.31); glyph.curve3(36.52, 37.21, 36.52, 30.71); glyph.LineTo(36.52, 15.53); glyph.curve3(36.52, 9.13, 36.77, 7.69); glyph.curve3(37.01, 6.25, 37.57, 5.76); glyph.curve3(38.13, 5.27, 38.87, 5.27); glyph.curve3(39.65, 5.27, 40.23, 5.62); glyph.curve3(41.26, 6.25, 44.19, 9.18); glyph.LineTo(44.19, 6.45); glyph.curve3(38.72, -0.88, 33.74, -0.88); glyph.curve3(31.35, -0.88, 29.93, 0.78); glyph.curve3(28.52, 2.44, 28.47, 6.45); glyph.ClosePolygon(); glyph.MoveTo(28.47, 9.62); glyph.LineTo(28.47, 26.66); glyph.curve3(21.09, 23.73, 18.95, 22.51); glyph.curve3(15.09, 20.36, 13.43, 18.02); glyph.curve3(11.77, 15.67, 11.77, 12.89); glyph.curve3(11.77, 9.38, 13.87, 7.06); glyph.curve3(15.97, 4.74, 18.70, 4.74); glyph.curve3(22.41, 4.74, 28.47, 9.62); glyph.ClosePolygon(); Affine mtx = Affine.NewIdentity(); mtx *= Affine.NewScaling(4.0); mtx *= Affine.NewTranslation(220, 200); VertexSourceApplyTransform trans = new VertexSourceApplyTransform(glyph, mtx); FlattenCurves curve = new FlattenCurves(trans); CreateAndRenderCombined(graphics2D, stroke, curve); graphics2D.Render(stroke, new ColorF(0, 0, 0, 0.1).ToColor()); graphics2D.Render(curve, new ColorF(0, 0.6, 0, 0.1).ToColor()); } break; } }