Un tableau de toutes les cartes même le dos des cartes.
Code : Tout sélectionner
;
; This code is automatically generated by the FormDesigner.
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
; Event procedures needs to be put in another source file.
;
; EnableExplicit
Global Window_0
Global ScrollArea_0
Structure File
x.i
y.i
ImageID.i
ContainerID.i
ImageGadgetID.i
Text$
EndStructure
Global NewList File.File()
Declare ResizeGadgetsWindow_0()
Declare Affiche_cartes(type, debut, fin, x, y)
Procedure OpenWindow_0(x = 0, y = 0, width = 620, height = 400)
Window_0 = OpenWindow(#PB_Any, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
ScrollArea_0 = ScrollAreaGadget(#PB_Any, 10, 10, 600, 380, 780, 570, 1)
CloseGadgetList()
EndProcedure
Procedure ResizeGadgetsWindow_0()
Protected FormWindowWidth, FormWindowHeight
FormWindowWidth = WindowWidth(Window_0)
FormWindowHeight = WindowHeight(Window_0)
ResizeGadget(ScrollArea_0, 10, 10, FormWindowWidth - 20, FormWindowHeight - 20)
EndProcedure
Procedure Window_0_Events(event)
Select event
Case #PB_Event_SizeWindow
ResizeGadgetsWindow_0()
Case #PB_Event_CloseWindow
ProcedureReturn #False
Case #PB_Event_Menu
Select EventMenu()
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
EndSelect
EndSelect
ProcedureReturn #True
EndProcedure
OpenWindow_0()
#card_dll=0
Define path.s = "cards.dll" ;GetCurrentDirectory()+
OpenLibrary(#card_dll,path)
;{ Liste les fonctions de la dll
; If ExamineLibraryFunctions(#card_dll)
; Debug CountLibraryFunctions(#card_dll)
;
; While NextLibraryFunction()
; Debug LibraryFunctionName()
; Debug LibraryFunctionAddress()
;
; Wend
; EndIf
;}
Prototype.i Proto_cdtAnimate(DC,Card,X,Y,Etat)
Prototype.i Proto_cdtDraw(DC, X,Y,Card,Typ, Color);:TColor
Prototype.i Proto_cdtDrawExt(DC, X,Y,CardWidth,CardHeight,Card,Typ,Color);:TColor
Prototype.i Proto_dtInit(Width,Height)
Prototype.i Proto_dtTerm()
;Prototype.i Proto_WEP(); si dll en 16 bits
Global cdtAnimate.Proto_cdtAnimate = GetFunction(#card_dll, "cdtAnimate")
Global cdtDraw.Proto_cdtDraw = GetFunction(#card_dll, "cdtDraw")
Global cdtDrawExt.Proto_cdtDrawExt = GetFunction(#card_dll, "cdtDrawExt")
Global cdtInit.Proto_dtInit = GetFunction(#card_dll, "cdtInit")
Global cdtTerm.Proto_dtTerm = GetFunction(#card_dll, "cdtTerm")
;{
; function cdtAnimate(DC:HDC;Card,X,Y,Etat:Integer):Integer; StdCall; external 'CARDS.DLL';
; function cdtDraw(DC:HDC; X,Y,Card,Typ:Integer; Color:TColor):Integer; StdCall; external 'CARDS.DLL';
; function cdtDrawExt(DC:HDC; X,Y,CardWidth,CardHeight,Card,Typ:Integer; Color:TColor):integer; StdCall; external 'CARDS.DLL';
; function cdtInit(var Width,Height:Integer):Integer; StdCall; external 'CARDS.DLL';
; function cdtTerm:Integer; StdCall; external 'CARDS.DLL';
; function cdtDraw(DC:HDC; X,Y,Card,Typ:Integer; Color:TColor):Integer;
;
; Paramètre
;
; Description
; DC
; Handle du contexte de périphérique dans lequel le tracé de la carte à jouer sera effectuée.
; X,Y
; Position de la carte à jouer en pixel.
; Card
; Numéro (appelé égalemnt ID) de la carte à jouer.
; Typ
; Type de la carte. LES valeurs possibles sont "0", "1" et "2" (permet d'inverser les couleurs).
; Si le paramètre "Typ" vaut "1", le paramètre "Card" de la fonction "cdtDraw" possèdent également quinze autres valeures qui sont : "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "67" et "68".
; On peut remarquer que la valeur "66" n'existe pas.
; Color
; Couleur de fond de la carte. Par défaut, cette couleur est blanche.
;
; Ce tableau récapitule LES valeurs possibles du paramètre "Card" de la fonction "cdtDraw".
; trefle carreau coeur pique
;
; As 0 1 2 3
;
;
; Roi 48 49 50 51
;
;
; LES images qui sont affichées au dos de la carte à jouer peuvent être différentes en fonction
;des versions de Windows et donc de la DLL.
;
; Astuce : Lorsque le paramètre "Typ" de la fonction "cdtDraw" vaut "1", vous pouvez alors changer
;la couleur de fond des 52 cartes à jouer (ainsi que pour le dos de la carte "53") grâce au
;paramètre"Color".
;}
; //Initialise la DLL
Global TailleCarteW,TailleCarteH
; CallFunction(Dll_ID, "cdtInit", @TailleCarteW, @TailleCarteH)
cdtInit(@TailleCarteW, @TailleCarteH)
; Debug TailleCarteW
; Debug TailleCarteH
; Afficher cartes
OpenGadgetList(ScrollArea_0)
Global n=GadgetWidth(ScrollArea_0)/(TailleCarteW)
Define x=0
Define y=0
Define c=0
; mode 0 is "draw face card"
; For modes 0 And 2, the resource ID uses this formula
; resource id equals ((((card number SHL 2) mod 0dh) plus ((card number And
; 3) times 0dh)) plus 1)
;{ type 0 et 2
; Dim tab(255)
; For i=0 To 255
; ; ((((card number SHL 2) mod 0dh) plus ((card number And 3) times 0dh)) plus 1)
; ; a=((((Mod(i << 2)), 13) + ((i & 3) * 13)) + 1)
; a=i << 2
; b=Mod(a,13)
; c=i & 3
; c=c*13
; d=b+c+1
; tab(i)=d
; Debug d
; Next i
; SortArray(tab(),#PB_Sort_Ascending )
; Debug "================================="
; For i=0 To 255
; Debug tab(i) ; tab rempli de 1 à 52
; Next i
;}
Define Card_Type=0
y=Affiche_cartes(Card_Type, 0, 61, x, y); au dessus de 61 ça bug
; mode 1 is "draw back"
Card_Type=1
x=0
y=y+TailleCarteH+20
y=Affiche_cartes(Card_Type, 0, 255, x, y)
; mode 2 is "draw highlighted face card"
Card_Type=2
x=0
y=y+TailleCarteH+20
y=Affiche_cartes(Card_Type, 0, 51, x, y)
; mode 3 is "draw empty card spot"
Card_Type=3
x=0
y=y+TailleCarteH+20
y=Affiche_cartes(Card_Type, 0, 53, x, y)
; mode 4 is "erase card"
Card_Type=4
x=0
y=y+TailleCarteH+20
y=Affiche_cartes(Card_Type, 0, 255, x, y)
; mode 5 is "draw empty card spot but doesnt paint background"
Card_Type=5
x=0
y=y+TailleCarteH+20
y=Affiche_cartes(Card_Type, 0, 53, x, y)
; mode 6 is "draw red X card"
Card_Type=6
x=0
y=y+TailleCarteH+20
y=Affiche_cartes(Card_Type, 0, 67, x, y)
; mode 7 is "draw green O card"
Card_Type=7
x=0
y=y+TailleCarteH+20
y=Affiche_cartes(Card_Type, 0, 68, x, y)
; ; mode 8 et + ? à essayer sur les dll plus récentes
; Card_Type=8
; x=0
; y=y+TailleCarteH+20
; y=Affiche_cartes(Card_Type, 0, 255, x, y)
;Fermeture de la dll
cdtTerm()
Define event
Repeat
event=WaitWindowEvent()
Select event
Case #PB_Event_SizeWindow
ResizeGadgetsWindow_0()
EndSelect
Until event=#PB_Event_CloseWindow
Procedure Affiche_cartes(type, debut, fin, x, y)
Protected HDC, hdcc, ok, marge, z, marge_legende,c, index
For z=debut To fin
HDC = CreateImage(#PB_Any, TailleCarteW, TailleCarteH);,32,#PB_Image_Transparent )
If HDC
AddElement(File())
File()\ImageID = HDC
; Debug hdc
hdcc=StartDrawing(ImageOutput(HDC))
ok=cdtDraw(hdcc,0,0,z,Type,#White)
; Debug ok
StopDrawing()
EndIf
marge =0
marge_legende=30
If ok
File()\x=x
File()\y=y
x=x+TailleCarteW+marge
c=c+1
If c>n-1
c=0
x=0
y=y+TailleCarteH+marge+marge_legende
EndIf
File()\ContainerID = ContainerGadget(#PB_Any, File()\x, File()\y, TailleCarteW, TailleCarteH+marge_legende, #PB_Container_Flat)
File()\ImageGadgetID=ImageGadget(#PB_Any, 0, 0, TailleCarteW, TailleCarteH, ImageID(File()\ImageID))
TextGadget(#PB_Any, 0, TailleCarteH, TailleCarteW,marge_legende, "Type: "+Str(type)+" n°"+Str(z),#PB_Text_Center)
CloseGadgetList()
; Update the Gadget states and refresh the display
;
index = ListIndex(File())
SetGadgetAttribute(ScrollArea_0, #PB_ScrollArea_InnerHeight, (index+1)*TailleCarteH + 10)
While WindowEvent(): Wend
EndIf
Next z
ProcedureReturn y
EndProcedure
;{Explication
; After finding OUT that certain things I did when coding cards.dll (such As
; studying the complete code IN a disassembler) mean that any code I write
; For it a potential "derivitave work", I have come up With a descrition that
; is (hopefully) detailed enough To enable someone Else With windows GDI
; programming experience To write cards.dll For wine but (hopefully) Not
; detailed enough To be considered a "derivitive work"
;
; The folowing files can be made available To whoever ends up working on
; cards.dll:
; 1.cards.spec, a ready made spec file For the dll
; 2.cards.rc, a RC file containing the card bitmaps (which are licenced under
; a licence that gave permission To use them) And also the card back bitmaps
; that were sent To me before (To whoever ends up working on this, feel free
; To modify the images If you dont like them :)
; 3.makefile.IN ready made For the dll
; AND 4.cards.h which contains the publicly documented Interface To cards.dll
; (which I pulled from various info documents found on the net)
; IANAL but I dont think that any of these could be claimed To be covered by
; that "derivitave work" thing, If they are, please do tell me.
;
; This document explains the workings of cards.dll (version 5.00.2134.1 from
; windows XP SP1)
;
; Cards.dll exports 7 different functions.
; These are:
; cdtInit
; cdtTerm
; cdtAnimate
; cdtDraw
; cdtDrawExt
; DllMain
; AND WEP
;
; cdtInit takes 2 INT * variables. It should Return TRUE If the initalization
; was sucessfull And FALSE If it was Not.
; It is a place To do any initalization you require (depending on For example
; If you want To preload the resource bitmaps Or whatever).
; It should Return the x And y size of the card bitmaps IN the 2 variables.
; For the cards I am using, the x size is 71 And the y size is 96 (which just
; happened To match up With the size of microsofts cards which is good)
;
; the main purpose of DllMain is To store the HINSTANCE of the cards.dll To
; use later when the bitmaps are loaded
;
; WEP is a holdover from when cards.dll was a 16 bit dll And doesnt actually
; need To be implemented (since its never called by 32 bit windows)
;
; cdtTerm is where you undo anything you did IN cdtInit (such As unloading
; any preloaded resources)
; It takes no parameters And returns nothing.
;
; cdtAnimate is supposed To handle animations For the card backs but since
; the backs we are using dont animate, it can just Return TRUE
; (hence why the resource file I wrote returns the windows XP version number
; since XP doesnt have animated backs either)
; As For parameters, it takes a HDC, an x And y position And a frame number
; (each individual microsoft back has a specific number of frames And
; applictions tend To hard-code these values)
;
; cdtDraw basicly calls cdtDrawExt passing the Default size of the card
; bitmaps As the x And y size parameters
;
; The real work is done IN cdtDrawExt
; This function takes:
; a HDC (For the screen window To draw the card on)
; an X positon And a Y position To draw the card at
; a card number (cards.h lists the different values)
; a mode number (again cards.h lists the different values)
; AND a RGB background color
; What the function does depends on the value of the mode.
; If the upper bit of md (which is an INT) is set, then it shouldnt save And
; resore the corner pixels (As explained below)
;
; modes greater than 7 should (As far As I can tell) do nothing.
; mode 0 is "draw face card"
; mode 1 is "draw back"
; mode 2 is "draw highlighted face card"
; mode 3 is "draw empty card spot"
; mode 4 is "erase card"
; mode 5 is "draw empty card spot but doesnt paint background"
; mode 6 is "draw red X card"
; AND mode 7 is "draw green O card"
;
; all modes use the same "drawing logic" except For mode 4 which doesnt draw
; any bitmap.
;
; You need a resource ID And a raster OP To do the drawing
; For modes 0 And 2, the resource ID uses this formula
; resource id equals ((((card number SHL 2) mod 0dh) plus ((card number And
; 3) times 0dh)) plus 1)
; For mode 1, the resource ID is just the card number
; For modes 3 And 5, the resource ID is 53 (the resource ID of the empty card
; spot graphic, also the contant hb IN cards.h)
; For mode 1, the resource ID is just the card number
; For mode 6, the resource ID is 67 (the resource ID of the card With the red
; X on a green background graphic, also the contant xb IN cards.h)
; For mode 7, the resource ID is 68 (the resource ID of the card With the
; green O on a green background graphic, also the contant ob IN cards.h)
; AND mode 4 doesnt use any ID since it doesnt draw anything.
;
; For the raster OP, all modes use SRCCOPY except For:
; mode 2 which uses NOTSRCCOPY
; AND modes 3 And 5 which use SRCAND
;
; Also, If the mode is 0, the background color is set To white (0xFFFFFF)
; before drawing. And after drawing, If the card is a red card (resource IDs
; 0x0E To ox17 And 0x1B To 0x24), it paints over the boarders of the card
; using PatBlt And the BLACKNESS rasterop.
;
; If the mode is 3 Or 4, it creates a solid brush using the background color,
; uses SetBrushOrgEx To set the brush origin To the screen DC origin And then
; uses PatBlt To paint over the area of the card using PATCOPY.
;
; If the mode has the top bit clear (As explained above) And the size matches
; With the Default card size, before drawing, it saves the corner pixels of
; the cards (the card bitmaps I am using have one pixel IN each corner) And
; then Restore them after drawing.
;
; To do the actual drawing, you need To load the bitmap resource INTO memory
; AND load the resulting HBITMAP INTO a memory DC.
; You also need To set the background color of the screen DC To whatever was
; passed in (unless its mode 0, IN which Case its 0xFFFFFF As explained
; above). And then, you need To copy the Data from the memory DC To the
; screen DC using either BitBlt Or StretchBlt As appropriate.
;
; Remeber To free all the GDI resources (bitmaps, memory DCs etc) that you used.
; AND also To Restore the background color To whatever it was
; before you changed it.
; If the function is a sucess, you Return TRUE.
; If the function is a failure (e.g. a GDI function CALL fails), you Return
; FALSE.
;
; Hoepfully someone can use this information To implement cards.dll IN a way
; that is legally safe.
;}
Mesa.