DEFINT a-z

REM $INCLUDE Graphics.bh
REM $INCLUDE Exec.bc

LIBRARY OPEN "graphics.library", LIBRARY_MINIMUM&

CONST length% = 40, skew% = 15, xstart% = 260, ystart% = 110
fb$ = "HiSoft BASIC 2"

'
'SafeSetOutlinePen, a backwards (<V39 graphics) compatible SetOutlinePen
'
SUB SafeSetOutlinePen(BYVAL w&, BYVAL c)
	STATIC junk&

	IF PEEKW(LIBRARY("graphics.library") + lib_Version) >= 39 THEN
		junk& = SetOutlinePen&(w&, c)
	ELSE
		POKEB w& + AOlPen, c
		POKEW w& + RastPortFlags, PEEKW(w& + RastPortFlags) OR AREAOUTLINE&
	END IF
END SUB

REM Sub-program to draw a 3-D box with a letter
SUB draw_box(BYVAL rp&, BYVAL x, BYVAL y, ch$)
STATIC ch_x, ch_y, junk&

REM Draw outline of a box
	SetAPen rp&, 0	' set foreground pen to background color
	junk& = AreaMove(rp&, x, y)
	junk& = AreaDraw(rp&, x + skew, y - skew)
	junk& = AreaDraw(rp&, x + length + skew, y - skew)
	junk& = AreaDraw(rp&, x + length + skew, y + length - skew)
	junk& = AreaDraw(rp&, x + length, y + length)
	junk& = AreaDraw(rp&, x, y + length)
	junk& = AreaEnd(rp&)

REM Now draw 3 lines to complete 3-D box
	SetAPen rp&, 1	' select standard pen
	Move rp&, x, y
	Draw rp&, x + length, y
	Draw rp&, x + length + skew, y - skew

	Move rp&, x + length, y + length
	Draw rp&, x + length, y
	
REM Draw the letter text, centred in the box
	ch_x = TextLength&(rp&, SADD(ch$), LEN(ch$))
	ch_y = PEEKW(rp& + TxHeight)
	Move rp&, x + (length - ch_x) / 2, y + (length + ch_y) / 2
	Text rp&, SADD(ch$), LEN(ch$)
END SUB

REM The main program

'force the BASIC runtime library to initialise TmpRas & AreaInfo in the default
'window's RastPort (!)
AREAFILL

SafeSetOutlinePen WINDOW(8), 1	'set the outline pen color

draw_box WINDOW(8), xstart, ystart, "B"
draw_box WINDOW(8), xstart + 7 * length / 6, ystart, "C"
draw_box WINDOW(8), xstart + 7 * length / 12, ystart - 7 * length / 6, "A"

fb_width = TextLength&(WINDOW(8), SADD(fb$), LEN(fb$))
fb_height = PEEKW(WINDOW(8) + TxHeight)
fb_x = xstart + (13 * length \ 6 + skew - fb_width) \ 2
fb_y = ystart + length + fb_height * 3 \ 2

REM Display picture title
Move WINDOW(8), fb_x, fb_y
Text WINDOW(8), SADD(fb$), LEN(fb$)

END
