Fix for a crash which happened when a document couldn't be opened.
[AROS-Contrib.git] / fish / surf / bezpt.c
blob3c07546f3b622079418b9764df03100becd2b87a
1 #include <aros/oldprograms.h>
2 #include "mytypes.h"
3 #include "scrnio.h"
4 #include "control.h"
5 #include "bezpt.h"
7 BezCoord Bezpt[MaxSegs+1];
9 int NumBezPts;
10 int ActSeg;
11 bool SegDrawn;
12 int BezMesh = DefBezMeshVal;
13 float BezStepSize = 1.0/DefBezMeshVal;
15 void DrawBox(int, int, int);
16 void DrawSqr(int, int, int);
17 void DrawPnt(int, int, int);
18 void DrawLine(int, int, int, int, int);
19 void ClrWindow(bool);
21 void SetBezMesh( value )
22 int value;
24 BezMesh = value;
25 BezStepSize = 1.0/value;
29 void ClearSegments()
31 NumBezPts = 0;
32 ActSeg = 0;
36 static float xa, xb, xc, xd;
37 static float ya, yb, yc, yd;
39 * start up calculations that must be performed before calling
40 * CalcBezPt on any given segment
42 void InitCalcBez()
44 xa = -StartPtX(ActSeg) + 3.0*( Cntrl1X(ActSeg) - Cntrl2X(ActSeg))
45 + EndPtX(ActSeg);
46 xb = 3.0 *( StartPtX(ActSeg) + Cntrl2X(ActSeg) - 2.0*Cntrl1X(ActSeg));
47 xc = 3.0*( Cntrl1X(ActSeg) - StartPtX(ActSeg));
48 xd = StartPtX(ActSeg);
50 ya = -StartPtY(ActSeg) + 3.0*( Cntrl1Y(ActSeg) - Cntrl2Y(ActSeg))
51 + EndPtY(ActSeg);
52 yb = 3.0 *( StartPtY(ActSeg) + Cntrl2Y(ActSeg) - 2.0*Cntrl1Y(ActSeg));
53 yc = 3.0*( Cntrl1Y(ActSeg) - StartPtY(ActSeg));
54 yd = StartPtY(ActSeg);
58 * calculate a point on the bezier curve of a segment
60 void CalcBezPt( t, xvp, yvp)
61 float t;
62 float *xvp, *yvp;
64 *xvp = (( t*xa + xb) * t + xc) *t + xd;
66 *yvp = (( t*ya + yb) * t + yc) *t + yd;
71 void XdrawBezSeg()
73 float t;
74 float ftox, ftoy;
75 int fromx, fromy, tox, toy;
77 InitCalcBez();
78 for( fromx = StartPtX(ActSeg), fromy = StartPtY(ActSeg), t=BezStepSize;
79 t < 1.0; fromx = tox, fromy = toy, t+= BezStepSize ) {
81 CalcBezPt( t, &ftox, &ftoy );
82 tox = (int)ftox;
83 toy = (int)ftoy;
84 DrawLine( fromx, fromy, tox, toy, XOR );
85 DrawPnt( tox, toy, XOR );
87 DrawLine( fromx, fromy, EndPtX(ActSeg), EndPtY(ActSeg),XOR);
92 void XdrawAllBezSegs()
94 ResetActSeg();
95 do {
96 XdrawBezSeg();
97 NextSeg();
98 } while( ActSeg);
100 DrawStartPt(); /* Leonards changes */
101 DrawEndPt(); /* Leonards changes */
102 DrawControl0();
103 DrawControl1();
108 void ResetCurve()
110 if( NumBezPts > 0 && CurMode == FITBEZIER ) {
111 int i;
113 ClrWindow(true);
114 for( i = 0; i < NumBezPts; i++ ) {
115 Bezpt[i].x.cur1 = Bezpt[i].x.prev2 = Bezpt[i].x.cur0;
116 Bezpt[i].y.cur1 = Bezpt[i].y.prev2 = Bezpt[i].y.cur0;
118 ActSeg = 0;
120 XdrawAllBezSegs();
126 * set the value of a bezpt element
128 static void SetBezPt( xval, yval )
129 int xval, yval;
131 BezVal *i;
133 i = &Bezpt[NumBezPts-1].x;
134 i->cur0 = i->prev2 = i->cur1 = xval;
135 i = &Bezpt[NumBezPts-1].y;
136 i->cur0 = i->prev2 = i->cur1 = yval;
142 void InitBezPt(xval,yval)
143 int xval, yval;
145 int segno;
147 NumBezPts++;
148 SetBezPt(xval,yval);
149 segno = NumBezPts -2;
150 if( segno >= 0) {
152 DrawLine( StartPtX( segno), StartPtY(segno),
153 EndPtX( segno), EndPtY(segno), XOR );
161 void EditBezPt(xval, yval)
162 int xval, yval;
164 int segno = NumBezPts -2;
166 DrawLine( StartPtX(segno), StartPtY(segno),
167 EndPtX( segno ), EndPtY(segno), XOR );
169 SetBezPt(xval, yval);
171 DrawLine( StartPtX( segno), StartPtY(segno),
172 EndPtX( segno), EndPtY(segno), XOR );