1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
#region paramètres
public struct _Page
{
public float XEcranSourisDepart, YEcranSourisDepart; // Translation de la vue, Point de départ
public float DeltaXVue, DeltaYVue; // Translation de la vue
public float DeltaXVuePrecedent, DeltaYVuePrecedent; // Translation de la vue
public float AncienXEcranSourisDepart, AncienYEcranSourisDepart; // Zoom de la vue
public float WindowsClippingReelXmini; // utilisé pour le clipping
public float WindowsClippingReelXmaxi; // utilisé pour le clipping
public float WindowsClippingReelYmini; // utilisé pour le clipping
public float WindowsClippingReelYmaxi; // utilisé pour le clipping
}
public struct Segment2
{
public float X0, Y0, X1, Y1;
}
public struct _Profil
{
public int NbSegment;
public Segment2[] Segment;
}
public int nbProfil;
public _Profil[] profil;
#endregion
public void Render(Form1 form)
{
Graphic.BeginDraw();
// Colorie le fond du panel
Graphic.Clear(backGroundColor);
// Positionne la vue avec la souris(DeltaXVue et deltaYVue)
Matrix3x2 mTranslation = Matrix3x2.Translation(Page.DeltaXVue, Page.DeltaYVue);
Vector2 v = new Vector2(0.0f, 0.0f); // Centre du zoom
Matrix3x2 mScaling = Matrix3x2.Scaling(Page.Zoom, Page.Zoom, v);
Graphic.Transform = Matrix3x2.Multiply(mScaling, mTranslation);
// Définit la fenêtre de clipping réel
Page.WindowsClippingReelXmini = Page.XReelPivot + (0 + Page.DeltaXVuePrecedent - Page.DeltaXVue - Page.AncienXEcranSourisDepart);
Page.WindowsClippingReelXmaxi = Page.XReelPivot + (LargeurVue + Page.DeltaXVuePrecedent - Page.DeltaXVue - Page.AncienXEcranSourisDepart);
Page.WindowsClippingReelYmini = HauteurVue - (Page.YReelPivot + (HauteurVue + Page.DeltaYVuePrecedent - Page.DeltaYVue - Page.AncienYEcranSourisDepart));
Page.WindowsClippingReelYmaxi = HauteurVue - (Page.YReelPivot + (0 + Page.DeltaYVuePrecedent - Page.DeltaYVue - Page.AncienYEcranSourisDepart));
// stroke
StrokeStyleProperties strokeProperties = new StrokeStyleProperties() { StartCap = CapStyle.Round, EndCap = CapStyle.Round };
StrokeStyle stroke = new StrokeStyle(Factory, strokeProperties);
// Dessine
float x0 = profil[i].Segment[0].X0; // P0
float y0 = profil[i].Segment[0].Y0; //P0
float x1 = 0.0f;
float y1 = 0.0f;
int j = 0;
for (j = 0; j < NbSegment; j ++) // NbSegment très grand
{
x1 = profil[i].Segment[profil[i].NbSegment - 1].X1; // P1
y1 = profil[i].Segment[profil[i].NbSegment - 1].Y1; // P1
#region Clipping de P0P1
float x1Sauve = x1;
float y1Sauve = y1;
if ((x0 < Page.WindowsClippingReelXmini) && (x1 < Page.WindowsClippingReelXmini))
goto suite;
if ((x0 > Page.WindowsClippingReelXmaxi) && (x1 > Page.WindowsClippingReelXmaxi))
goto suite;
if ((y0 < Page.WindowsClippingReelYmini) && (y1 < Page.WindowsClippingReelYmini))
goto suite;
if ((y0 > Page.WindowsClippingReelYmaxi) && (y1 > Page.WindowsClippingReelYmaxi))
goto suite;
float dx = x1 - x0;
float dy = y1 - y0;
if (ClipOneEnd(ref x0, ref y0, dx, dy) && ClipOneEnd(ref x1, ref y1, dx, dy))
Graphic.DrawLine(new Vector2(x0, HauteurVue - y0), new Vector2(x1, HauteurVue - y1), brush, Epaisseur, stroke);
#endregion
suite:
x0 = x1Sauve;
y0 = y1Sauve;
}
// Fin du dessin
stroke.Dispose();
Graphic.EndDraw();
SwapChain.Present(0, PresentFlags.None);
#endregion
}
private bool ClipOneEnd(ref float x, ref float y, float dx, float dy)
{
if ((x >= Page.WindowsClippingReelXmini) && (x <= Page.WindowsClippingReelXmaxi) && (y >= Page.WindowsClippingReelYmini) && (y <= Page.WindowsClippingReelYmaxi))
return true;
if ((x < Page.WindowsClippingReelXmini) && ((dx * (Page.WindowsClippingReelYmini - y) - dy * (Page.WindowsClippingReelXmini - x)) * (dx * (Page.WindowsClippingReelYmaxi - y) - dy * (Page.WindowsClippingReelXmini - x)) <= 0))
{
y += (Page.WindowsClippingReelXmini - x) * dy / dx;
x = Page.WindowsClippingReelXmini;
return true;
}
else if ((x > Page.WindowsClippingReelXmaxi) && ((dx * (Page.WindowsClippingReelYmini - y) - dy * (Page.WindowsClippingReelXmaxi - x)) * (dx * (Page.WindowsClippingReelYmaxi - y) - dy * (Page.WindowsClippingReelXmaxi - x)) <= 0))
{
y += (Page.WindowsClippingReelXmaxi - x) * dy / dx;
x = Page.WindowsClippingReelXmaxi;
return true;
}
if ((y < Page.WindowsClippingReelYmini) && ((dx * (Page.WindowsClippingReelYmini - y) - dy * (Page.WindowsClippingReelXmini - x)) * (dx * (Page.WindowsClippingReelYmini - y) - dy * (Page.WindowsClippingReelXmaxi - x)) <= 0))
{
x += (Page.WindowsClippingReelYmini - y) * dx / dy;
y = Page.WindowsClippingReelYmini;
return true;
}
else if ((y > Page.WindowsClippingReelYmaxi) && ((dx * (Page.WindowsClippingReelYmaxi - y) - dy * (Page.WindowsClippingReelXmini - x)) * (dx * (Page.WindowsClippingReelYmaxi - y) - dy * (Page.WindowsClippingReelXmaxi - x)) <= 0))
{
x += (Page.WindowsClippingReelYmaxi - y) * dx / dy;
y = Page.WindowsClippingReelYmaxi;
return true;
}
return false;
}
private void Panel1MouseDown(object sender, MouseEventArgs e)
{
if (Mode=-1)
{
// Translation vue
Page.XEcranSourisDepart = e.X;
Page.YEcranSourisDepart = e.Y;
Mode=0;
return;
}
if (Mode == 0)
{
// translation vue
Mode = -1;
Page.DeltaXVuePrecedent += e.X - Page.XEcranSourisDepart;
Page.DeltaYVuePrecedent += e.Y - Page.YEcranSourisDepart;
Page.AncienXEcranSourisDepart += (int)(e.X - Page.XEcranSourisDepart);
Page.AncienYEcranSourisDepart += (int)(e.Y - Page.YEcranSourisDepart);
return;
}
}
private void Panel1MouseMove(object sender, MouseEventArgs e)
{
if (Mode == 0)
{
// Translation vue
Page.DeltaXVue = Page.DeltaXVuePrecedent + e.X - Page.XEcranSourisDepart;
Page.DeltaYVue = Page.DeltaYVuePrecedent + e.Y - Page.YEcranSourisDepart;
return;
}
} |
Partager