/*
		MSE DPaint Assistant

		$VER: 05 Oct 1996
*/

signal on syntax
address DPAINT.1

Font = "Topaz2p"; FontSize = 8; FontBaseLine = 6
tweenW = 10; tweenH = 12; ScreenW = 640; ScreenH = 400; SliderW = 100

/* Widths for WidthOfText() */
W. = 8
W.49 = 6  /* 1 */
W.73 = 5  /* I */
W.84 = 7  /* T */
W.105 = 4 /* i */
W.107 = 7 /* k */
W.108 = 4 /* l */
W.116 = 7 /* t */

'LockGUI'
'Title' OFF; 'Panel' OFF; 'Magnify' OFF
'SetRGB' 0 160 160 160
'SetRGB' 1 0 0 0
'SetRGB' 2 256 256 256
'SetRGB' 3 96 112 144

'SetBGColor' 0; 'SetFGColor' 1
'DeleteFrames' ALL
'Clear' ALL
'SetFont' Font' 'FontSize
'LoadBrush' "TEMP:DPaint.brush"
'CopyBrush'

'Text' 0 0 "" /* Bypass bug in DPaint */

nFrames = 1; cX = 0; cY = 0; incrY = 0
call open(Labels, "TEMP:DPaint.names")
do until eof(Labels)
	t = readln(Labels); if t = "" then leave
	parse var t Mode' 'Parameters

	Mode = upper(Mode)
	select
		when Mode = "GROUPTITLE" then do
			parse var Parameters W t
			t = t" "
			call CheckFit(W, FontSize+9)
/*t = cX cY*/
			'SetFGColor' 3
			'Rect' cX cY W-1 FontSize+8 FILL
			wt = WidthOfText(t)
			'SetFGColor' 1
			'Text' cX+((W-wt)%2) cY+5+FontBaseLine '"'t'"'
			cX = cX + W + tweenW
			end

		when Mode = "LABELBAR" then do
			parse var Parameters W t
			t = t" "
			call CheckFit(W, FontSize)
/*t = cX cY*/
			sY = cY + (FontBaseLine % 2) - 1
			'SetPen' 0
			'SetFGColor' 2
			'Line' cX sY cX+W sY
			'SetFGColor' 1
			'Line' cX sY+1 cX+W sY+1
			'SetFGColor' 0
			wt = WidthOfText(t)
			'Rect' cX+((W-wt)%2) sY wt-1 1
			'SetFGColor' 1
			'Text' cX+((W-wt)%2) cY+FontBaseLine '"'t'"'
			cX = cX + W + tweenW
			end

		when Mode = "NEWROW" then do
			cX = 0; cY = cY + incrY + tweenH; incrY = 0
			end

		when Mode = "SLIDER" then do
			parse var Parameters t
			call CheckFit(SliderW, FontSize+24)
/*t = cX cY*/
			wt = WidthOfText(t)
			'Text' cX+((SliderW-wt)%2) cY+FontBaseLine '"'t'"'
			'MoveTo' X cX+50 Y cY+22
			'PasteBrush'
			'MButtons' SELECTDOWN
			'MButtons' SELECTUP
			cX = cX + SliderW + tweenW
			end

		otherwise
			nop
	end
end

call close(Labels)
/*'SaveAnim' "TEMP:MSE-Gadgets.anim" FORCE*/
'GotoFrame' 1
'Title' ON
'PasteBrush'
'SetPen' 0
'UnlockGUI'
exit


WidthOfText: procedure expose W.
	parse arg t

	tW = 0
	do lp = 1 to length(t)
		u = c2d(substr(t,lp,1))
		tW = tW + W.u
	end
return tW-1

CheckFit: procedure expose cX cY ScreenW ScreenH incrY tweenH nFrames
	arg w,h

	if cX + w > ScreenW then do
		cX = 0; cY = cY + incrY + tweenH
		incrY = h
	end
	if cY + incrY > ScreenH then do
		nFrames = nFrames + 1
		'SetFrames' nFrames
		'GotoFrame' nFrames
		'Clear' CURRENT
		cX = 0; cY = 0
		incrY = h
		end
	else
		if h > incrY then incrY = h
return

syntax:
	'UnlockGUI'
	exit
