;
; drag.sh
;
; Support code for dragging operations
;
;  1995-1998 Straylight
;

;----- Licensing note -------------------------------------------------------
;
; This file is part of Straylight's Sapphire library.
;
; Sapphire is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2, or (at your option)
; any later version.
;
; Sapphire is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with Sapphire.  If not, write to the Free Software Foundation,
; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

;----- Overview -------------------------------------------------------------
;
; Functions provided:
;
;  drag_start
;  drag_scroll
;  drag_setDash
;  drag_cancel
;  drag_redraw
;  drag_eorColour

		[	:LNOT::DEF:drag__dfn
		GBLL	drag__dfn

; --- drag_start ---
;
; On entry:	R0 == window containing the drag
;		R1 == flags word (see flags below)
;		R2 == pointer to drag routine
;		R3 == magic number to pass in R9
;		R4 == value to pass to routine in R10
;		R5 == value to pass to routine in R12
;
; On exit:	--
;
; Use:		Starts a drag operation.  Any outstanding drag operation
;		is cancelled on the assumption that someone stole our
;		UserDragBox event.

		IMPORT	drag_start

; --- drag_scroll ---
;
; On entry:	R1 == pointer to window state block
;
; On exit:	R2,R3 == new scroll positions to set
;		R14 == R1+20 (pointer to scroll offsets)
;
; Use:		Works out the scroll positions which should be set to auto-
;		scroll the window.  The algorithm is simple: the window is
;		scrolled so that the point beneath the mouse pointer is
;		within the window's visible work area.

		IMPORT	drag_scroll

; --- drag_setDash ---
;
; On entry:	R0 == dash pattern byte
;
; On exit:	--
;
; Use:		Sets the dash pattern to be the given value.

		IMPORT	drag_setDash

; --- drag_cancel ---
;
; On entry:	--
;
; On exit:	--
;
; Use:		Cancels the current drag operation.

		IMPORT	drag_cancel

; --- drag_redraw ---
;
; On entry:	R1 == pointer to redraw block
;
; On exit:	--
;
; Use:		Redraws the drag box, if the redraw takes place in the
;		currently dragging window.

		IMPORT	drag_redraw

; --- drag_eorColour ---
;
; On entry:	R0 == colour A
;		R1 == colour B
;
; On exit:	--
;
; Use:		Sets the foreground colour to be an EOR colour such that
;		when painted over Wimp colour A, it appears as Wimp colour B.

		IMPORT	drag_eorColour

;----- Flags ----------------------------------------------------------------

drFlag_noUpdate	EQU	(1<<0)			;Don't generate update events

;----- Drag handler events --------------------------------------------------

; --- Note ---
;
; The events which request that you draw something are called for each
; rectangle of the draw operation -- i.e. do not call Wimp_GetRectangle
; because this is done for you.

		^	0
drEvent_draw	#	1			;Draw dragged object
						;R1 == pointer to redraw blk
						;R2,R3 == drag start posn
						;R4,R5 == drag current posn
						;R6,R7 == window origin
						;Dash pattern set up

drEvent_undraw	#	1			;Undraw dragged object
						;Regs as for drEvent_draw
						;Normally use the same code

drEvent_update	#	1			;Redraw dragged object in
						;place
						;Regs as for drEvent_draw
						;Dash pattern set up so that
						;single plot will rotate box,
						;so may share code with
						;drEvent_draw

drEvent_trans	#	1			;Translate coordinates
						;R1 == ptr to window state
						;R4,R5 == pointer position
						;R6,R7 == window origin
						;Translate pointer position
						;to internal coordinates if
						;this is useful to you.
						;Return new coords in R4,R5

drEvent_getPos	#	1			;Read pointer position
						;R1 == ptr to window state
						;R2,R3 == start position
						;R4,R5 == pointer position
						;R6,R7 == window origin
						;Used to read pointer posn.
						;Do any grid snapping here
						;and return with R4,R5 as
						;coords to use.

drEvent_done	#	1			;Drag operation completed
						;R1 == ptr to window state
						;R2,R3 == drag start posn
						;R4,R5 == drag current posn

drEvent_cancel	#	1			;Drag operation aborted
						;No other registers set up

		]

;----- That's all, folks ----------------------------------------------------

		END
