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

	include 'pl.equ'
;-----------------------------------------------
;
;   Imported addresses
;
;-----------------------------------------------

	IMPORT	D_Deref
	IMPORT	P_AddObjRgn
	IMPORT	P_DrawRgn
	IMPORT	P_ObjList
	IMPORT	P_RemoveObj
	IMPORT	P_ToolType
	IMPORT	T_Dispose



;--------------------------------------------------------------------------
;
; P_SetObjAttr (Attr:w; NewValue:w)
;

P_SetObjAttr	PROC		EXPORT
			;Using P_Data
			;Using P_ObjData

		INPUT Attr:w,NewValue:w
		LOCAL ObjHdl:l,ObjPtr:l,UpdateRgn:l,ObjType:w

		BEGIN

		lda P_ToolType
		jne Exit

		tool _NewRgn,out=(UpdateRgn:l)


		movelong P_ObjList,ObjHdl
WhileLoop
		cpzl ObjHdl
		jeq EndLoop

		rcall D_Deref,in=(ObjHdl:ax),out=(ObjPtr:ax)

		moveword [ObjPtr]:#P_Selected,a
		jeq NextObject
		moveword [ObjPtr]:#P_Type,ObjType
		cmp #P_ALPHA
		jeq NextObject

		lda Attr
		asl a
		tax
		jmp (JumpTable,x)


ChangeFill
		lda ObjType
		cmp #P_RECTANGLE
		blt NextObject
		cmp #P_CIRCLE+1
		bge NextObject
		moveword NewValue,[ObjPtr]:#P_ObjFilled
		bra AddObj


ChangePen
		cmpw ObjType,#P_CIRCLE+1
		bge NextObject
		call P_AddObjRgn,in=(ObjPtr:l,UpdateRgn:l)
		moveword NewValue,[ObjPtr]:#P_PenSize
		bra AddObj


ChangeColor
		cmpw ObjType,#P_PICTURE
		bge NextObject
		moveword NewValue,[ObjPtr]:#P_ObjColor
		bra AddObj


ChangeFont
		jsr IsPageDate
		bcc NextObject
		moveword NewValue,[ObjPtr]:#P_ItemFontID
		bra AddObj

ChangeStyle
		jsr IsPageDate
		bcc NextObject
		movebyte NewValue,[ObjPtr]:#P_ItemFontID+2
		bra AddObj

ChangeSize
		jsr IsPageDate
		bcc NextObject
		movebyte NewValue,[ObjPtr]:#P_ItemFontID+3




AddObj
		call P_AddObjRgn,in=(ObjPtr:l,UpdateRgn:l)

NextObject
		tool _HUnlock,in=(ObjHdl:l)
		movelong [ObjPtr],ObjHdl
		brl WhileLoop


EndLoop
		call P_DrawRgn,in=(UpdateRgn:l)


Exit	RETURN


; Returns with carry set if it is a page or date object

IsPageDate
		lda ObjType
		cmp #P_PAGETOOL
		blt @Clear
		cmp #P_DATETOOL+1
		bge @Clear
		sec
		rts
@Clear	clc
		rts


JumpTable	DC.W	ChangeFill
	DC.W	ChangePen
	DC.W	ChangeColor
	DC.W	ChangeFont
	DC.W	ChangeStyle
	DC.W	ChangeSize

		ENDP





;-----------------------------------------------------------------------------
;
; P_SetDelFlag (Value:w)
;

P_SetDelFlag	PROC		EXPORT
			;Using P_Data
			;Using P_ObjData

		INPUT Value:w
		LOCAL ObjHdl:l,ObjPtr:l

		BEGIN

		movelong P_ObjList,ObjHdl

ObjLoop	cpzl ObjHdl
		beq Exit

		movelong [ObjHdl],ObjPtr
		moveword [ObjPtr]:#P_Selected,a
		beq NextObj

		moveword Value,[ObjPtr]:#P_Deleted

NextObj
		movelong [ObjPtr],ObjHdl
		bra ObjLoop


Exit	RETURN
		ENDP





;------------------------------------------------------------------------------
;
; P_DelMarkObj ()
;
; Deletes are objects that are marked as deleted from the object list.

P_DelMarkObj	PROC		EXPORT
			;Using P_Data
			;Using P_ObjData

		LOCAL ObjHdl:l,ObjPtr:l,NextObj:l

		BEGIN

		movelong P_ObjList,ObjHdl

While	cpzl ObjHdl
		jeq EndWhile

		movelong [ObjHdl],ObjPtr
		movelong [ObjPtr],NextObj

		moveword [ObjPtr]:#P_Deleted,a
		beq TryNext

; need to do more if Q_Text object or picture
		moveword [ObjPtr]:#P_Type,a
		cmp #P_Alpha
		bne NotAlpha
		call T_Dispose,in=(ObjHdl:l,#0:w)
		bra Dispose

NotAlpha	cmp #P_PICTURE
		bne Dispose
		tool _KillPicture,in=([ObjPtr]:#P_PictHandle:l)


Dispose
		call P_RemoveObj,in=(ObjHdl:l)
		tool _DisposeHandle,in=(ObjHdl:l)


TryNext	movelong NextObj,ObjHdl
		brl While
EndWhile


		RETURN
		ENDP
		END

