Nice clean example, Sparkie. It's just missing a couple of features: transparent card drawing, backs and placeholders. I'm not really planning to release a compiled lib this time around as it's fairly short, so here's my includefile offering that works like this:
-cardnumbers start at the ace and go 1-13
-suits are clubs, diamonds, hearts, spades: 1-4
-suit 5 are the 13 available cardbacks
-suit 6 has two cardnumbers, 1 and 2 for the two placeholders
do:
result=InitCards(transcolor) ; transcolor is the color of your table
A result of 1 means a successful initialization of the cards. You can now do:
ImageID=GetCard(cardnumber,suit) for any card, back or placeholder.
It's actually far simpler to use than my original lib compiled for 3.94. That one is deprecated now.
Here's the code:
Code: Select all
;========================================================
; Program: PureCardDraw.pbi
; Author: netmaestro
; Date: November 14, 2006
; Target OS: MS Windows All
; Target Compiler: PureBasic Version 4.0+
; License: Totally free and unrestricted
; Credit appreciated, not required
;========================================================
#Clubs = 1
#Diamonds = 2
#Hearts = 3
#Spades = 4
#Back = 5
#PlaceHolder = 6
#Jack = 11
#Queen = 12
#King = 13
Global Dim Cards(13,6)
ProcedureDLL InitCards(transcolor)
lib = OpenLibrary(#PB_Any,"cards.dll")
If lib
CallFunction(lib,"cdtInit",@w.l,@h.l)
;Card fronts
For i=1 To 13
For j=1 To 5
CurCard = CreateImage(#PB_Any, 71, 96, 24)
Cards(i,j) = ImageID(CurCard)
hdc = StartDrawing(ImageOutput(CurCard))
Box(0,0,71,96,transcolor)
If j=#Back
CallFunction(lib,"cdtDraw",hdc,0,0,i+52,1,RGB(100,200,100))
Else
CallFunction(lib,"cdtDraw",hdc,0,0,(i-1)*4+j-1,0,0)
EndIf
StopDrawing()
Next
Next
;Placeholders
For i=1 To 2
CurCard = CreateImage(#PB_Any, 71, 96, 24)
Cards(i,6) = ImageID(CurCard)
hdc = StartDrawing(ImageOutput(CurCard))
Box(0,0,71,96,transcolor)
CallFunction(lib,"cdtDraw",hdc,0,0,i+66,1,0)
StopDrawing()
Next
CallFunction(lib,"cdtTerm")
CloseLibrary(1)
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndProcedure
ProcedureDLL GetCard(value, suit)
ProcedureReturn Cards(value, suit)
EndProcedure
And here's the obligatory test proggie:
Code: Select all
IncludeFile "PureCardDraw.pbi"
InitCards(RGB(0,128,0))
OpenWindow(0, 0, 0, 1000, 700, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(0,RGB(0,128,0))
CreateGadgetList(WindowID(0))
For i=1 To 13
ImageGadget(#PB_Any,75*i-65,60,0,0,GetCard(i,#Clubs))
ImageGadget(#PB_Any,75*i-65,160,0,0,GetCard(i,#Diamonds))
ImageGadget(#PB_Any,75*i-65,260,0,0,GetCard(i,#Hearts))
ImageGadget(#PB_Any,75*i-65,360,0,0,GetCard(i,#Spades))
ImageGadget(#PB_Any,75*i-65,460,0,0,GetCard(i,#Back))
Next
ImageGadget(#PB_Any,10,560,0,0,GetCard(1,#PlaceHolder))
ImageGadget(#PB_Any,85,560,0,0,GetCard(2,#PlaceHolder))
Repeat
Event.l = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow