Skip to content

Commit

Permalink
Fix : Move,Scale,Rotate Arrows
Browse files Browse the repository at this point in the history
Oups forgotten ;)
  • Loading branch information
pubpub-zz committed Aug 22, 2021
1 parent 71fdcd6 commit 4129ab1
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/ArrowSelDlg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ private void SaveBtn_Click(object sender, EventArgs e)
Bitmap bmp = Root.FormCollection.PrepareArrowBitmap(ArrowHead, EditStroke.DrawingAttributes.Color, EditStroke.DrawingAttributes.Transparency,
Root.HiMetricToPixel(EditStroke.DrawingAttributes.Width), (float)theta, out l1);
Root.FormCollection.StoredArrowImages[(int)EditStroke.ExtendedProperties[Root.ARROWSTART_GUID].Data]=bmp;
EditStroke.ExtendedProperties.Add(Root.ARROWSTART_FN_GUID, ArrowHead);

Root.FormCollection.StoredArrowImages[(int)EditStroke.ExtendedProperties[Root.ARROWEND_GUID].Data].Dispose();
bmp = Root.FormCollection.PrepareArrowBitmap(ArrowTail, EditStroke.DrawingAttributes.Color, EditStroke.DrawingAttributes.Transparency,
Root.HiMetricToPixel(EditStroke.DrawingAttributes.Width), (float)(Math.PI + theta), out l1);
Root.FormCollection.StoredArrowImages[(int)EditStroke.ExtendedProperties[Root.ARROWEND_GUID].Data] = bmp;
EditStroke.ExtendedProperties.Add(Root.ARROWEND_FN_GUID, ArrowTail);

Root.UponAllDrawingUpdate = true;
DialogResult = DialogResult.Cancel;
Expand Down
64 changes: 59 additions & 5 deletions src/FormCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2124,8 +2124,48 @@ void ModifyProperties(Stroke s)
s.ExtendedProperties.Add(Root.TEXTHEIGHT_GUID, ((double)(s.ExtendedProperties[Root.TEXTHEIGHT_GUID].Data) * k));
s.ExtendedProperties.Add(Root.ROTATION_GUID, (double)s.ExtendedProperties[Root.ROTATION_GUID].Data + deg);
}
if (s.ExtendedProperties.Contains(Root.ARROWSTART_GUID))
{
//Point p = new Point((int)s.ExtendedProperties[Root.ARROWSTART_X_GUID].Data,(int)s.ExtendedProperties[Root.ARROWSTART_Y_GUID].Data);
Double theta;
Point p = s.GetPoint(0);
Point p1 = s.GetPoint(1);
theta = Math.Atan2(p1.Y - p.Y, p1.X - p.X);
int i = (int)s.ExtendedProperties[Root.ARROWSTART_GUID].Data;
string fn = (string)s.ExtendedProperties[Root.ARROWSTART_FN_GUID].Data;
int l;
StoredArrowImages[i].Dispose();
Console.WriteLine("W= {0}", s.DrawingAttributes.Width);
double kk = Math.Max(1,s.DrawingAttributes.Width * 0.037795280352161);// code copied from Root.HiMetricToPixel in order to not have rounding;
StoredArrowImages[i] = PrepareArrowBitmap(fn, s.DrawingAttributes.Color, s.DrawingAttributes.Transparency, (int)Math.Ceiling(kk), (float)theta, out l);
kk = kk / 18.0f;
IC.Renderer.InkSpaceToPixel(Root.FormDisplay.gOneStrokeCanvus, ref p);
p.Offset((int)Math.Round(-kk*(300.0/2-l) * Math.Cos(theta)),(int)Math.Round(-kk*(300.0 / 2 - l) * Math.Sin(theta)));
s.ExtendedProperties.Add(Root.ARROWSTART_X_GUID, (int)p.X);
s.ExtendedProperties.Add(Root.ARROWSTART_Y_GUID, (int)p.Y);
}
if (s.ExtendedProperties.Contains(Root.ARROWEND_GUID))
{
//Point p = new Point((int)s.ExtendedProperties[Root.ARROWEND_X_GUID].Data,(int)s.ExtendedProperties[Root.ARROWEND_Y_GUID].Data);
Double theta;
Point p = s.GetPoint(1);
Point p1 = s.GetPoint(0);
theta = Math.Atan2(p1.Y - p.Y, p1.X - p.X);
int i = (int)s.ExtendedProperties[Root.ARROWEND_GUID].Data;
string fn = (string)s.ExtendedProperties[Root.ARROWEND_FN_GUID].Data;
int l;
StoredArrowImages[i].Dispose();
double kk = Math.Max(1, s.DrawingAttributes.Width * 0.037795280352161);// code copied from Root.HiMetricToPixel in order to not have rounding;
StoredArrowImages[i] = PrepareArrowBitmap(fn, s.DrawingAttributes.Color, s.DrawingAttributes.Transparency, (int)Math.Ceiling(kk), (float)theta, out l);
kk = kk / 18.0f;
IC.Renderer.InkSpaceToPixel(Root.FormDisplay.gOneStrokeCanvus, ref p);
p.Offset((int)Math.Round(-kk * (300.0 / 2 - l) * Math.Cos(theta)), (int)Math.Round(-kk * (300.0 / 2 - l) * Math.Sin(theta)));
s.ExtendedProperties.Add(Root.ARROWEND_X_GUID, (int)p.X);
s.ExtendedProperties.Add(Root.ARROWEND_Y_GUID, (int)p.Y);
}
}

if (k == 0)
return;
Matrix m = new Matrix(1, 0, 0, 1, 0, 0);
m.Translate(+Xc, +Yc);
m.Scale((float)k, (float)k);
Expand All @@ -2135,9 +2175,11 @@ void ModifyProperties(Stroke s)
{
if (double.IsNaN(Sel.GetBoundingBox().Width * k))
return;
Sel.Transform(m, applyOnPen);
Sel.Transform(m, false);
foreach (Stroke s in Sel)
{
if (applyOnPen)
s.DrawingAttributes.Width = (float)(s.DrawingAttributes.Width * k);
if (s.Deleted)
continue;
ModifyProperties(s);
Expand All @@ -2147,7 +2189,9 @@ void ModifyProperties(Stroke s)
{
if (double.IsNaN(Hover.GetBoundingBox().Width * k))
return;
Hover.Transform(m, applyOnPen);
if (applyOnPen)
Hover.DrawingAttributes.Width = (float)(Hover.DrawingAttributes.Width * k);
Hover.Transform(m, false);
ModifyProperties(Hover);
}
}
Expand Down Expand Up @@ -3060,6 +3104,8 @@ private void IC_CursorInRange(object sender, InkCollectorCursorInRangeEventArgs

public void MoveStrokeAndProperties(Stroke movedStroke, int DeltaX, int DeltaY, bool moveStroke = true)
{
Point m = new Point(DeltaX, DeltaY);
IC.Renderer.InkSpaceToPixel(Root.FormDisplay.gOneStrokeCanvus, ref m);
if (movedStroke==null||movedStroke.Deleted)
return;

Expand All @@ -3080,8 +3126,6 @@ public void MoveStrokeAndProperties(Stroke movedStroke, int DeltaX, int DeltaY,
}
if (movedStroke.ExtendedProperties.Contains(Root.LISTOFPOINTS_GUID))
{
Point m = new Point(DeltaX, DeltaY);
IC.Renderer.InkSpaceToPixel(Root.FormDisplay.gOneStrokeCanvus, ref m);
int ii = (int)movedStroke.ExtendedProperties[Root.LISTOFPOINTS_GUID].Data;
//StoredPatternPoints[ii].ForEach(pt => pt.Offset(DeltaX, DeltaY));
ListPoint lst = StoredPatternPoints[ii];
Expand All @@ -3091,6 +3135,16 @@ public void MoveStrokeAndProperties(Stroke movedStroke, int DeltaX, int DeltaY,
lst[i] = pt;
}
}
if(movedStroke.ExtendedProperties.Contains(Root.ARROWSTART_X_GUID))
{
movedStroke.ExtendedProperties.Add(Root.ARROWSTART_X_GUID, (int)movedStroke.ExtendedProperties[Root.ARROWSTART_X_GUID].Data + m.X);
movedStroke.ExtendedProperties.Add(Root.ARROWSTART_Y_GUID, (int)movedStroke.ExtendedProperties[Root.ARROWSTART_Y_GUID].Data + m.Y);
}
if (movedStroke.ExtendedProperties.Contains(Root.ARROWEND_X_GUID))
{
movedStroke.ExtendedProperties.Add(Root.ARROWEND_X_GUID, (int)movedStroke.ExtendedProperties[Root.ARROWEND_X_GUID].Data + m.X);
movedStroke.ExtendedProperties.Add(Root.ARROWEND_Y_GUID, (int)movedStroke.ExtendedProperties[Root.ARROWEND_Y_GUID].Data + m.Y);
}
}

public Double StrokeLength(Stroke st)
Expand Down

0 comments on commit 4129ab1

Please sign in to comment.