
	load 'macros.dump'
	include 'driver.equ'
	include 'pl.equ'

;-----------------------------------------------
;
;   Imported addresses
;
;-----------------------------------------------

	IMPORT	D_Deref
	IMPORT	DoneH
	IMPORT	DoneV
	IMPORT	P_ContentRect
	IMPORT	P_Do_Ruler
	IMPORT	P_FullPaperRect
	IMPORT	P_H
	IMPORT	P_HRulRect
	IMPORT	P_PageMode
	IMPORT	P_PaperRect
	IMPORT	P_PortRect
	IMPORT	P_PrintHand
	IMPORT	P_V
	IMPORT	P_VRulRect
	IMPORT	D_Set4Pat
	IMPORT	D_UnLock


;----------------------------------------------------------------------
;
; Draw Rulers
;

P_DrawRulers	PROC		EXPORT

			;Using P_Data
			;Using P_RulerData
			;Using P_IconData

		input rgnhdl:l
		local tmprect:r,counter:w,offset:w,printstuff:l,vert:l
		local horz:l,ppp:w,startloc:w,tmp:l,ppfp:w,rgnptr:l

		begin +b

		call D_Set4Pat,in=(#LightYellow:w)

		moveword #P_TabWTop,tmprect
		moveword #P_TabWBottom,tmprect+4
		moveword P_VRulRect+2,tmprect+2
		moveword P_VRulRect+6,tmprect+6

		tool _ClipRect,in=(!tmprect:l)
		tool _PaintRect,in=(!tmprect:l)
		_PenNormal

		rcall D_Deref,in=(P_PrintHand:ax),out=(printstuff:ax)

		moveword [printstuff]:#4,vert
		moveword [printstuff]:#6,horz
		stz vert+2
		stz horz+2

		rcall D_UnLock,in=(P_PrintHand:ax)

		rcall D_Deref,in=(rgnhdl:ax),out=(rgnptr:ax)

;		 ; Horizontal ruler
		moverect P_HRulRect,tmprect
		moveword P_VRulRect+2,tmprect+2
		tool _RectInRgn,in=(!tmprect:l,rgnhdl:l),out=(a:w)
		jeq CkVert

		subword P_PaperRect+6,P_PaperRect+2,ppp

; do D_Update Q_Rect!?!?!
		subword P_ContentRect+2,P_H,startloc
		lda P_PageMode
		bne DoHPage
		tool _Long2Fix,in=(horz:l),out=(horz:l)
		bra DoHoriz

DoHPage	moveword P_FullPaperRect+2,startloc
		subword P_FullPaperRect+6,P_FullPaperRect+2,ppfp
		tool _Multiply,in=(horz:w,ppfp:w),out=(tmp:l)
		tool _FixDiv,in=(tmp:l,#0:w,ppp:w),out=(horz:l)


DoHoriz
		pushlong horz
		pushword startloc
		cmpw [rgnptr]:#4,P_ContentRect+2
		blt HContent1
		and #$FFFE
		pushword a

		bra HCk
HContent1	pushword P_ContentRect+2

HCk	cmpw [rgnptr]:#8,P_ContentRect+6
		blt HContent2
		pushword P_ContentRect+6
		bra DoneH
HContent2	pushword a

DoneH	; in :l,:w,:w,:w
		in #0:w,#P_HRulRect:l,#P_VRulRect:l,#P_PortRect:l
		in #P_ContentRect:l,P_Pagemode:w
		xcall P_Do_Ruler


;		 ; Vertical ruler

CkVert	tool _RectInRgn,in=(#P_VRulRect:l,rgnhdl:l),out=(a:w)
		jeq exit

		subword P_PaperRect+4,P_PaperRect,ppp
		subword P_ContentRect,P_V,startloc
		lda P_PageMode
		bne DoVPage
		tool _Long2Fix,in=(vert:l),out=(vert:l)
		bra DoVert

DoVPage	moveword P_FullPaperRect,startloc
		subword P_FullPaperRect+4,P_FullPaperRect,ppfp
		tool _Multiply,in=(vert:w,ppfp:w),out=(tmp:l)
		tool _FixDiv,in=(tmp:l,#0:w,ppp:w),out=(vert:l)

DoVert

		pushlong vert
		pushword startloc
		cmpw [rgnptr]:#2,P_ContentRect
		blt VContent1
		pushword a
		bra VCk
VContent1	pushword P_ContentRect

VCk	cmpw [rgnptr]:#6,P_ContentRect+4
		blt VContent2
		pushword P_ContentRect+4
		bra DoneV
VContent2	pushword a

DoneV	; in :l,:w,:w,:w
		in #1:w,#P_HRulRect:l,#P_VRulRect:l,#P_PortRect:l
		in #P_ContentRect:l,P_Pagemode:w
		xcall P_Do_Ruler


Exit	rcall D_UnLock,in=(rgnhdl:ax)
		_PenNormal

		return
		ENDP
		END

