LIBRARY rexxgui
DO
FUNCDEF("GetDC", "void, void", "user32")
FUNCDEF("ReleaseDC", ", void, void", "user32")
paintstruct = "32u, 32, 32u, 32u, 32u, 32u, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32"
FUNCDEF("BeginPaint", "32u, void, struct PAINTSTRUCT stor", "user32")
FUNCDEF("EndPaint", "32, void, struct PAINTSTRUCT", "user32")
rect = "32u,32u,32u,32u"
FUNCDEF("InvalidateRect", "32, void, struct RECT, 32u", "user32")
FUNCDEF("cdtInit", "32, 32 * stor, 32 * stor", "cards32")
FUNCDEF("cdtDrawExt", "32, void, 32, 32, 32, 32, 32, 32, 32", "cards32")
FUNCDEF("cdtDraw", "32, void, 32, 32, 32, 32, 32", "cards32")
FUNCDEF("cdtTerm", "32,", "cards32")
CATCH FAILURE
CONDITION("M")
RETURN
END
DO
guierr = "SYNTAX"
guiheading = 1
guicreatewindow('NORMAL')
guisetctlplacement('ClickToDeal', cardwidth + 5 + 5 + 4, windowheight - (54 + (cardheight % 2)))
CATCH SYNTAX
CONDITION('M')
IF EXISTS(cardwidth) THEN cdtterm()
RETURN
END
again:
DO FOREVER
guigetmsg()
CATCH SYNTAX
CONDITION('M')
SIGNAL again
FINALLY
IF EXISTS(cardwidth) THEN cdtterm()
guidestroywindow()
END
createdrawpile: PROCEDURE; USE ARG pile., numdecks
pile.total = numdecks * 52
cardnum = 0
DO numdecks
DO j = 1 TO 52
cardnum = cardnum + 1
pile.cardnum = j - 1
END
END
DO i = 1 FOR cardnum - 1
j = RANDOM(i, cardnum)
IF j > i THEN PARSE VALUE pile.i pile.j WITH pile.j pile.i
END
pile.0 = 1
RETURN
nextcardfrompile: PROCEDURE; USE ARG pile.
IF pile.0 > pile.total THEN RETURN ""
card = pile.[pile.0]
pile.0 = pile.0 + 1
RETURN card
isanotherinpile: PROCEDURE; USE ARG pile.
IF pile.0 > pile.total THEN RETURN ""
card = pile.[pile.0]
RETURN card
dealcard:
IF isanotherinpile(pile.) == "" THEN RETURN
cardnum = cardnum + 1
cardrow.cardnum = nextcardfrompile(pile.)
IF isanotherinpile(pile.) == "" THEN pileback = 67
SIGNAL forcerepaint
cardbackcrosshatch:
cardback = 53
SIGNAL newcardback
cardbackweave1:
cardback = 54
SIGNAL newcardback
cardbackweave2:
cardback = 55
SIGNAL newcardback
cardbackrobot:
cardback = 56
SIGNAL newcardback
cardbackflowers:
cardback = 57
SIGNAL newcardback
cardbackvine1:
cardback = 58
SIGNAL newcardback
cardbackvine2:
cardback = 59
SIGNAL newcardback
cardbackfish1:
cardback = 60
SIGNAL newcardback
cardbackfish2:
cardback = 61
SIGNAL newcardback
cardbackshells:
cardback = 62
SIGNAL newcardback
cardbackcastle:
cardback = 63
SIGNAL newcardback
cardbackisland:
cardback = 64
SIGNAL newcardback
cardbackcardhand:
cardback = 65
SIGNAL newcardback
newcardback:
IF isanotherinpile(pile.) \== "" THEN pileback = cardback
forcerepaint:
invalidaterect(guiwindow)
RETURN
cardbackexit:
guisendmsg(, 'POST CLOSE')
RETURN
wm_paint:
hdc = beginpaint(guiwindow, paintstruct)
paint(hdc)
endpaint(guiwindow, paintstruct)
RETURN ""
paint:
x = 5
DO i = 1 TO cardnum
cdtdraw(ARG(1), x, 5, cardrow.i)
x = x + 14
END
cdtdraw(ARG(1), 5, cardheight + 10, pileback, 1)
IF discardedcard == "" THEN cdtdraw(ARG(1), windowwidth - (cardwidth + 14), cardheight + 10, 68, 1)
ELSE cdtdraw(ARG(1), windowwidth - (cardwidth + 14), cardheight + 10, discardedcard)
RETURN
wm_lbuttondblclk:
wm_lbuttondown:
mousedown(hdc, ARG(2), ARG(3))
RETURN ""
mousedown: USE ARG hdc, x, y
IF y < cardheight + 5 THEN DO
IF cardnum > 0 THEN DO
discardedcard = cardrow.cardnum
cardnum = cardnum - 1
rect.1 = windowwidth - (cardwidth + 14)
rect.2 = cardheight + 10
rect.3 = rect.1 + cardwidth
rect.4 = rect.2 + cardheight
invalidaterect(guiwindow, rect)
rect.1 = 5 + 14 * cardnum
rect.2 = 5
rect.3 = rect.1 + cardwidth
rect.4 = rect.2 + cardheight
invalidaterect(guiwindow, rect, 1)
END
END
ELSE IF y > cardheight + 10 & y < (cardheight * 2) + 10 THEN DO
IF x > 5 & x < cardwidth + 5 THEN dealcard()
END
RETURN
wm_create:
i = cdtinit(cardwidth, cardheight)
IF i == 0 THEN DO
guisay("Problem initializing Cards32.DLL")
RETURN
END
cardback = 54
pileback = 54
discardedcard = ""
cardnum = 0
createdrawpile(pile., 1)
RETURN 0
wm_initdialog:
windowwidth = (14 * 51) + cardwidth + 5 + 5
windowheight = (2 * cardheight) + 5 + 5 + 15
guisetctlplacement(,,, windowwidth, windowheight, 'INNER')
RETURN |
|