
	include "blitbuts"

	setlace 0
	setblack
	module "director:modules/filereq"
	rows = WB.rows
	if rows < 350 then rows = rows+rows
	
	new 2,WB.columns,rows,1
	load 1,"director:tools/BlitU.Screen"
	display 1
	free 2
	speed 1
	filereq "screen","director",145,18
	color 17,1,1,1
	color 18,12,3,3
	color 19,10,10,10
	
	dim name[100],1
	dim objfile[100],1
	dim bkgfile[100],1
	dim postfix[100],1
	objfile[1] = 0
	bkgfile[1] = 0
	postfix[1] = 0
	appendflag = 0
	transflag = 0
	objbuf = 0
	bkgbuf = 0
	abort 0
	pointer 1
	mouse 2
	bbuf=1
	
	gosub f.clear
	
/main:
	set t
	if t then note "Stack creep error"
	
	display 1
	drawmode 0
	pen 1,1
	rect 160,5,527,78
	move 280,15
	pen 1,3
	text count;" blit";
	if count#1 then text "s";
	drawmode -1
	gosub waste
	getmouse x,y,b
	if (b ^ 1) = 0 then goto main
	
	gosub dobuttons
	goto main
	
/dobuttons:
	do blitbuts,x,y
	return
	
/f.done: close:end

/f.clear:
	count = 0
	bx = -1
	mods = 0
	obuf=1
	close
	mode=1
	open mode,"ram:dir_clip"
	if mode=0
	filereq "yesno"," OK "," OK ","Can't Open Clip File, RAM:dir_clip"
		end
	endif

;/in:
	setblack 1
	display 1
	fade -8
	return
	
/f.pick:
	if objbuf=0 then gosub f.object
	if objbuf=0 then return
	fade -8
	display objbuf
	fade -8
	gosub dobox	
	bx=x
	by=y
	bw=(x2+1)-x
	bh=(y2+1)-y
	fade -8
	display 1
	fade -8
	return
	
/f.transp:
	pen 1,3
	drawmode 2
	rect 23,111,144,124
	drawmode -1
	transflag=1-transflag
	return
	
/bprep:
	if bx=-1 then gosub f.pick
	if bx=-1 then return
	if bkgbuf=0 then gosub f.backgd
	if bkgbuf=0 then return
	fade -8
	newfast 10,1
	copy 1,10
	display objbuf
	free 1
	new 1,bkgbuf
	copy bkgbuf,1
	display 1
	fade -8	
	gosub dopos
	if b ^ 2
		cancel=1
	else 
		cancel=0
	endif
	fade -8
	display objbuf
	if cancel=0 then copy 1,bkgbuf		:rem  make perm
	free 1
	new 1,10
	copy 10,1
	free 10
	display 1
	fade -8		
	return
	
/f.blit:
	gosub bprep
	if cancel | bkgbuf=0 then return
	name[1]=9,0
	write name$;"BLIT ";obuf;",";bx;",";by;",";x2;",";y2;",";bw;",";bh;
	name[1]=':',0
	if postfix[1]
		write name$;postfix
	else
		write
	endif
	count=count+1
	return
	
/f.wipe:
	gosub bprep
	if cancel then return
	pen 1,0
	for i=0 to 3
		move 216+i*70,48
		draw 216+i*70,70
		draw 270+i*70,70
		draw 270+i*70,48
		draw 216+i*70,48
	next
rem  down arrow
	move 243,48
	draw 243,70
	draw 260,59
	move 243,70
	draw 226,59
	rect 216,48,270,53

rem  rt arrow
	i = 1
	move 216+i*70,59
	draw 270+i*70,59
	draw 243+i*70,65
	move 270+i*70,59
	draw 243+i*70,53
	rect 216+i*70,48,226+i*70,70
	
rem  up arrow
	i = 2	
	move 243+i*70,70
	draw 243+i*70,48
	draw 260+i*70,59
	move 243+i*70,48
	draw 226+i*70,59
	rect 216+i*70,65,270+i*70,70
	
rem  left arrow
	i=3
	move 270+i*70,59
	draw 216+i*70,59
	draw 243+i*70,65
	move 216+i*70,59
	draw 243+i*70,53
	rect 260+i*70,48,270+i*70,70
	
	move 274,37
	drawmode 0
	text "Select Wipe Direction"
	drawmode -1
	
	dim wbutts[5,4],2
	for i=0 to 3
		wbutts[1+i,1]=216+70*i,48,54,22
	next
	wbutts[5,1]=-1
	
/wipeb:
	getmouse x,y
	button b,x,y,wbutts	
	if b=0 then goto wipeb
	b=b-1
	name[1]=9,0
	write name$;"WIPE ";obuf;",";bx;",";by;",";x2;",";y2;",";bw;",";bh;
	if b ^ 1
		a = bh
	else 
		a = bw
	endif
	a=a/2
	write ",";a;",";b;
	name[1]=':',0
	if postfix[1]
		write name$;postfix
	else
		write
	endif
	count=count+1
	return
	
	
/f.dissolve:
	gosub bprep
	if cancel then return
	name[1]=9,0
write name$;"DISSOLVE ";obuf;",";bx;",";by;",";x2;",";y2;",";bw;",";bh;
	name[1]=':',0
	if postfix[1]
		write name$;postfix
	else
		write
	endif
	count=count+1
	return
	
/f.object:
	filereq "file",""
	filereq v,"select","Object Image","LOAD",name
	if v<0 then note "File Requester Error";v:return
	if v=0 then return		:rem  cancelled
	objfile$=name$
	objbuf=3
	load objbuf,objfile$	
	pen 1,0
	rect 153,132,573,145
	pen 1,3
	move 159,142
	text objfile$;
	if mods then obuf=obuf+1
	goto obpaint
	
/f.objbuf:
	move 588,142
	pen 1,3
	name$=obuf
	edit name$,2
	obuf=name$

/obpaint:
	pen 1,0
	rect 583,131,616,146
	move 588,142
	pen 1,3
	text obuf;
	return
	
/f.backgd:
	filereq "file",""
	filereq v,"select","Background Image","LOAD",name
	if v<0 then note "File Requester Error";v:return
	if v=0 then return		:rem  cancelled
	bkgfile$=name$
	bkgbuf=2
	loadfast bkgbuf,bkgfile$
	pen 1,0
	rect 154,150,573,164
	pen 1,3
	move 159,161
	text bkgfile$;
	return
	
/f.postfix:	
	move 158,179
	pen 1,3
	edit postfix$,56
	return
	
/dobox:
	resolution -1,xmax,ymax,d
	xmax=xmax-1
	ymax=ymax-1
	repeat		:rem make sure button is not still down before we start
		ifmouse x,y,b
	until b = 0
	pointer 2
	mouse 3		:rem continuous mouse, no pause
	x = -1
	drawmode 2
	pen 1,31
	
/dobtop
	getmouse x2,y2,b
	if x # -1
		move x,0:draw x,ymax
		move 0,y:draw xmax,y
	endif
	x=x2
	y=y2
	move x,0:draw x,ymax
	move 0,y:draw xmax,y
	if (b ^ 1) = 0 then goto dobtop		:rem  no button, followmouse
	x3=-1
/dobtop2:
	getmouse x2,y2,b
	if x3 # -1
		move x3,0:draw x3,ymax
		move 0,y3:draw xmax,y3
	endif	
	x3=x2
	y3=y2
	move x3,0:draw x3,ymax
	move 0,y3:draw xmax,y3
	if b ^ 1 then goto dobtop2		:rem  while button, followmouse
	
	mouse 2		:rem  now back to normal mouse mode
	gosub waste
	move x3,0:draw x3,ymax
	move 0,y3:draw xmax,y3
	move x,0:draw x,ymax
	move 0,y:draw xmax,y
	drawmode -1
	pointer 1
	if x>x2
		t=x
		x=x2
		x2=t
	endif
	if y>y2
		t=y
		y=y2
		y2=t
	endif
	return
	
/waste:
	repeat
		ifmouse aa,bb		:rem  waste any pending mouse clicks
	until aa=-1
	return
	
/dopos:
	resolution -1,x,y,b
	oldx = x/2
	oldy=y/2
	pointer 2
	repeat		:rem make sure button is not still down before we start
		ifmouse x,y,b
	until b = 0
	mouse 3		:rem continuous mouse, no pause
	tog=1
	handle=0
	
/doptop:
	ifkey key
	if key='h' | key='H'
		handle=1-handle
		x2=oldx
		y2=oldy
		if handle=0
			x2=oldx+bw
			y2=oldy+bh
		endif
	else
		ifmouse x2,y2,b
	endif
	if x2 == -1 & b == 0
		tog=1-tog
;		pause 7
		if tog=0 then pause 7:copy bkgbuf,1		:rem  restore bkgd
		pause 2
	else
		tog=1
		if handle
			oldx = x2-bw
			oldy = y2-bh
		else
			oldx=x2
			oldy=y2
		endif
	endif
	if tog & oldx != -1
		copy bkgbuf,1		:rem  restore bkgd
		if transflag then transparent 1
		blit objbuf,bx,by,oldx,oldy,bw,bh
		if transflag then transparent 0
	endif
	if b=0 then goto doptop
	mouse 2
	gosub waste
	pointer 1
	x2=oldx
	y2=oldy
	return
	
