home *** CD-ROM | disk | FTP | other *** search
- (***********************************************************)
- (* *)
- (* TURBO GRAPHIX version 1.06A *)
- (* *)
- (* Axis drawing module *)
- (* Module version 1.06A *)
- (* *)
- (* Copyright (C) 1985 by *)
- (* BORLAND International *)
- (* *)
- (***********************************************************)
-
- procedure DrawAxis(XDens, YDens, XLeft, YTop, XRight, YBottom,
- XAxis, YAxis : integer; Arrows : boolean);
- var
- LineStyleLoc, Xk0, Yk0, Xk1, Yk1, Xk2, Yk2, NDiff, X2, Y2,
- MaxExponentX, MaxExponentY, I, Ys, Xs, Delta, NPoints : integer;
- Difference, Number, S, Fract : real;
- X1RefLoc, X2RefLoc, Y1RefLoc, Y2RefLoc,
- X1RefLoc2, X2RefLoc2, Y1RefLoc2, Y2RefLoc2 : integer;
- ClippingLoc, DirectModeLoc, HeaderLoc : boolean;
-
- function StringNumber(X1 : real; MaxExponent : integer) : WrkString;
- var
- Y : WrkString;
- begin
- Str(X1 * Exp(-MaxExponent * Ln(10.0)):5:2, Y);
- StringNumber := Y;
- end; { StringNumber }
-
- function GetExponent(X1 : real) : integer;
- begin
- GetExponent := 0;
- if X1 <> 0.0 then
- if abs(X1) >= 1.0 then
- GetExponent := trunc(Ln(abs(X1)) / Ln(10.0))
- else
- GetExponent := -trunc(abs(Ln(abs(X1))) / Ln(10.0) + 1.0);
- end; { GetExponent }
-
- procedure DrawNum(X1, Y1, MaxExponent : integer; Number : real);
- var
- I : integer;
- StrNumber : WrkString;
- begin
- StrNumber := StringNumber(Number, MaxExponent);
- Y1 := Y1 - 3;
- for I := 1 to 5 do
- DrawAscii(X1, Y1, 1, Ord(StrNumber[I]));
- end; { DrawNum }
-
- function Balance : integer;
- begin
- Balance := 0;
- S := S + Fract;
- if S >= 0 then
- begin
- S := S - 1.0;
- Balance := 1;
- end;
- end; { Balance }
-
- procedure DrawExponent(X1, Y1, MaxExponent : integer);
- var
- I : integer;
- StrNumber : WrkString;
- begin
- Y1 := Y1 - 3;
- X1 := X1 + 1;
- DrawAscii(X1, Y1, 1, 49);
- DrawAscii(X1, Y1, 1, 48);
- Str(MaxExponent:3, StrNumber);
- Y1 := Y1 - 3;
- X1 := X1 - 7;
- for I := 1 to 3 do
- DrawAscii(X1, Y1, 1, Ord(StrNumber[I]));
- end; { DrawExponent }
-
- begin { DrawAxis }
- LineStyleLoc := LinestyleGlb;
- SetLineStyle(0);
- DirectModeLoc := DirectModeGlb;
- DirectModeGlb := true;
- with Window[WindowNdxGlb] do
- begin
- X1RefLoc := X1;
- X2RefLoc := X2;
- Y1RefLoc := Y1;
- Y2RefLoc := Y2;
- ReDefineWindow(WindowNdxGlb, X1 + XLeft, Y1 + YTop,
- X2 - XRight, Y2 - YBottom);
- SelectWindow(WindowNdxGlb);
- end;
- if (XDens < 0) xor (YDens < 0) then
- begin
- HeaderLoc := HeaderGlb;
- HeaderGlb := false;
- DrawBorder;
- HeaderGlb := HeaderLoc;
- end;
- XDens := abs(XDens);
- YDens := abs(YDens);
- if XDens > 9 then
- XDens := 0;
- if YDens > 9 then
- YDens := 0;
- Xk0 := (X1RefGlb + 4) shl 3;
- Yk0 := Y2RefGlb - 14;
- Yk1 := Y1RefGlb + 6;
- Xk1 := Xk0;
- Yk2 := Yk0;
- Xk2 := (X2RefGlb - 2) shl 3 + 7;
- if (XAxis >= 0) or (YAxis >= 0) then
- begin
- ClippingLoc := ClippingGlb;
- ClippingGlb := true;
- with Window[WindowNdxGlb] do
- begin
- X1RefLoc2 := X1;
- X2RefLoc2 := X2;
- Y1RefLoc2 := Y1;
- Y2RefLoc2 := Y2;
- end;
- ReDefineWindow(WindowNdxGlb, X1RefLoc2 + 4, Y1RefLoc2 + 6,
- X2RefLoc2 - 2, Y2RefLoc2 - 14);
- SelectWindow(WindowNdxGlb);
- DirectModeGlb := false;
- if (XAxis >= 0) then
- begin
- SetLineStyle(XAxis);
- DrawLine(X1WldGlb, Y1WldGlb + Y2WldGlb, X2WldGlb, Y1WldGlb + Y2WldGlb);
- SetLineStyle(0);
- end;
- if (YAxis >= 0) then
- begin
- SetLinestyle(YAxis);
- DrawLine(0, Y1WldGlb, 0, Y2WldGlb);
- SetLineStyle(0);
- end;
- ClippingGlb := ClippingLoc;
- DirectModeGlb := true;
- ReDefineWindow(WindowNdxGlb, X1RefLoc2, Y1RefLoc2, X2RefLoc2, Y2RefLoc2);
- SelectWindow(WindowNdxGlb);
- end;
- if YDens >= 2 then
- begin
- DrawLine(Xk0, Yk0, Xk1, Yk1);
- if Arrows then
- begin
- DrawLine(Xk0, Yk1, Xk0 - 4, Yk1 + 4);
- DrawLine(Xk0, Yk1, Xk0 + 4, Yk1 + 4);
- DP(Xk0, Yk1 - 1);
- end;
- end;
- if XDens >= 2 then
- begin
- DrawLine(Xk0, Yk0, Xk2 + 1, Yk2);
- if Arrows then
- begin
- DrawLine(Xk2, Yk2, Xk2 - 4, Yk2 - 4);
- DrawLine(Xk2, Yk2, Xk2 - 4, Yk2 + 4);
- end;
- end;
- if (abs(Yk0 - Yk1) >= 35) and (abs(Xk2 - Xk1) >= 150) then
- begin
- DrawLine(Xk0, Yk0, Xk0 - 4, Yk0);
- DrawLine(Xk0, Yk0, Xk0, Yk0 + 4);
- Delta := Y2RefGlb - Y1RefGlb - 20;
- NPoints := Delta div 7;
- NDiff := Delta - (NPoints shl 3) + NPoints;
- if YDens >= 4 then
- begin
- if abs(Y2WldGlb) > abs(Y1WldGlb) then
- MaxExponentY := GetExponent(Y2WldGlb)
- else
- MaxExponentY := GetExponent(Y1WldGlb);
- DrawNum(X1RefGlb shl 3, Yk0 + 1, MaxExponentY, Y1WldGlb);
- if MaxExponentY <> 0 then
- DrawExponent(X1RefGlb shl 3 + 1, Yk1 + 2, MaxExponentY);
- end;
- Fract := NDiff / NPoints;
- S := -Fract;
- Ys := Yk0;
- Difference := (Y2WldGlb - Y1WldGlb) / NPoints;
- for I := 1 to NPoints do
- begin
- Ys := Ys - 7 - Balance;
- if (YDens > 2) and (Ys > Y1RefGlb + 13) then
- begin
- Number := Y1WldGlb + I * Difference;
- DrawLine(Xk0, Ys, Xk0 - 4, Ys);
- if YDens >= 4 then
- if I mod (10 - YDens) = 0 then
- DrawNum(X1RefGlb shl 3, Ys + 1, MaxExponentY, Number);
- end;
- end;
- if XDens >= 4 then
- begin
- if abs(X2WldGlb) > abs(X1WldGlb) then
- MaxExponentX := GetExponent(X2WldGlb)
- else
- MaxExponentX := GetExponent(X1WldGlb);
- DrawNum(Xk0 - 14, Yk0 + 10, MaxExponentX, X1WldGlb);
- if MaxExponentX <> 0 then
- DrawExponent(Xk2 - 13, Yk0 + 10, MaxExponentX);
- end;
- Delta := abs(X2RefGlb - X1RefGlb) shl 3 - 41;
- NPoints := Delta div 30;
- NDiff := Delta - (NPoints shl 5) + (NPoints shl 1);
- Fract := NDiff / NPoints;
- S := -Fract;
- Xs := Xk0 - 1;
- Difference := (X2WldGlb - X1WldGlb) / NPoints;
- for I := 1 to NPoints do
- begin
- Xs := Xs + 30 + Balance;
- if (XDens > 2) and (Xs < X2RefGlb shl 3 + 7 - 24) then
- begin
- Number := X1WldGlb + I * Difference;
- DrawLine(Xs, Yk0, Xs, Yk0 + 4);
- if XDens >= 4 then
- if I mod (10 - XDens) = 0 then
- DrawNum(Xs - 14, Yk0 + 10, MaxExponentX, Number);
- end;
- end;
- end;
- ReDefineWindow(WindowNdxGlb, X1RefLoc, Y1RefLoc, X2RefLoc, Y2RefLoc);
- SelectWindow(WindowNdxGlb);
- DirectModeGlb := DirectModeLoc;
- SetLineStyle(LineStyleLoc);
- AxisGlb := true;
- X1Glb := XLeft;
- X2Glb := XRight;
- Y1Glb := YTop;
- Y2Glb := YBottom;
- end; { DrawAxis }
-
- procedure ResetAxis;
- begin
- AxisGlb := true;
- end; { ResetAxis }