(***********************************************************) (* *) (* TURBO GRAPHIX version 1.05A *) (* *) (* Axis drawing module *) (* Module version 1.05A *) (* *) (* 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:integer; 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; 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; 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; function Balance:integer; begin Balance:=0; s:=s+Fract; if s>=0 then begin s:=s-1.0; Balance:=1; end; end; 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; 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=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; procedure ResetAxis; begin AxisGlb := true; end;