Multiple rotation de text en GDI
Bonsoir,
J'ai besoin de dessiner 3 string (à 120°) autour d'un cercle. De plus, ces string tournent autour de celui-ci tout en restant horizontales pour être lisible facilement.
J'ai créé une fonction qui positionne une string et je comptais répéter l'opération 3 fois. Mais ça ne fonctionne pas comme prévu je n'arrive pas à intégrer le décalage de 120° , les 2 dernières tournent autour de la première car les rotations s'additionnent.
Voici ma fonction
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| private void DrawText(Graphics myGraphics,int AngularPosition,string StrTmp, Font FntVerin,float VerticalTranslation)
{
myGraphics.TranslateTransform(0, -VerticalTranslation);
myGraphics.RotateTransform(-Rotation);
SizeF stringSize = new SizeF();
int stringWidth = 100;
StringFormat newStringFormat = new StringFormat();
newStringFormat.FormatFlags = StringFormatFlags.DirectionVertical;
stringSize = myGraphics.MeasureString(StrTmp, FntVerin, stringWidth, newStringFormat);
Point PtCircle = new Point();
PtCircle.X = (int)(Math.Cos(Rotation / 360.0 * Math.PI));
PtCircle.Y = (int)(Math.Sin(Rotation / 360.0 * Math.PI));
float DeltaX = 0.0f;
if (Rotation < 90) { DeltaX = (float)(Math.Sin(Rotation / 360.0 * Math.PI) + (stringSize.Height / 2)); }
else if (Rotation < 180) { DeltaX = (float)(Math.Sin((180.0 - Rotation) / 360.0 * Math.PI) + (stringSize.Height / 2)); }
else if (Rotation < 270) { DeltaX = (float)(Math.Sin((Rotation - 180.0) / 360.0 * Math.PI) - (stringSize.Height / 2)); }
else if (Rotation < 360) { DeltaX = (float)(Math.Sin((180.0 - (Rotation - 180.0)) / 360.0 * Math.PI) - (stringSize.Height / 2)); }
myGraphics.DrawString(StrTmp, FntVerin, Brushes.Blue, PtCircle.X - stringSize.Height / 2 + DeltaX, PtCircle.Y - stringSize.Width / 2);
myGraphics.TranslateTransform(0, VerticalTranslation);
} |
Merci pour votre aide