private void pnlEditor_MouseLeave(object sender, EventArgs e) { _indicator = null; _nearestLine = null; _newLineStart = null; DrawEverything(); }
private void pnlEditor_MouseMove(object sender, MouseEventArgs e) { bool drawNeeded = false; PointF logical = ToLogical(new Point(e.X, e.Y)); float nearestX = (float)Math.Round(logical.X); float nearestY = (float)Math.Round(logical.Y); if (_indicator.Value.X != nearestX || _indicator.Value.Y != nearestY) { _indicator = new PointF(nearestX, nearestY); drawNeeded = true; } FontLine _newNearest = FindNearestLine(logical); if ( (_newNearest == null && _nearestLine != null) || (_newNearest != null && _nearestLine == null) || (_newNearest != null && _nearestLine != null && _newNearest != _nearestLine) ) { _nearestLine = _newNearest; drawNeeded = true; } if (drawNeeded) { DrawEverything(); } lblLogicalCoordinate.Text = logical.ToString() + "| " + nearestX.ToString() + ", " + nearestY.ToString(); }
private void txtCharacter_TextChanged(object sender, EventArgs e) { btnSave.Enabled = pnlEditor.Enabled = txtCharacter.Text.Length == 1; if (txtCharacter.Text.Length > 0) { char c = txtCharacter.Text.ToCharArray()[0]; _fontLines = _file.LoadCharacter(c); } else { _fontLines = null; _nearestLine = null; _indicator = null; _newLineStart = null; } DrawEverything(); }
private FontLine FindNearestLine(PointF point) { if (_fontLines.Count == 0) { return(null); } FontLine ret = null; float closestDistance = float.MaxValue; foreach (FontLine line in _fontLines) { float distance = FindDistanceToSegment(point, line.P1, line.P2); if (distance < .1 && distance < closestDistance) { ret = line; } } return(ret); }
private void pnlEditor_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (_indicator == null) { _newLineStart = null; return; } if (_newLineStart == null) { _newLineStart = new PointF(_indicator.Value.X, _indicator.Value.Y); } else { if (_newLineStart.Value.X != _indicator.Value.X || _newLineStart.Value.Y != _indicator.Value.Y) { _fontLines.Add(new FontLine(_newLineStart.Value, _indicator.Value)); _newLineStart = null; } } } else if (e.Button == MouseButtons.Right) { if (_newLineStart != null) { _newLineStart = null; } else { if (_nearestLine != null) { _fontLines.Remove(_nearestLine); _nearestLine = null; } } } DrawEverything(); }
public FontLine Copy() { FontLine copy = new FontLine(P1, P2); return(copy); }