Help Needed to display stack of cards using GTK!
Hey Guys, I am building a cards game which displays a stack of Cards( Some thing like Solitaire). I was wondering you give me some advise regarding it? Also开发者_如何学Python if you could direct me to a tutorial for stuff like these( I am already going through the gtk doc).
You should check what have already be done in GnomeGames :
- Aisleriot
- Blackjack
Get the code and see how they have done it. It seems that they render each and every card : For example, in Aisleriot source code, in game.h, you have the definition of an ArSlot struct which stores all the cards of one slot. In there, you can see that they define the 'expansion' union which is just defining the offset between the cards.
So if you wish to create a heap of cards, you can draw each one of them, or if you consider it's too slow, just draw a few cards with a random offset of one or two pixels, and then draw the last card on the top : with this algorithm, your heap of cards looks like a heap, and it's quick to render on screen.
Unfortunately, there's no widget included in GTK+ that displays stack of cards, so yu have to write one yourself. You should use GtkDrawingArea (preferably by subclassing it), and in handler for expose_event
signal do your drawing stuff. To draw you can use either plain GDK which is more basic, or use Cairo, which is more flexible drawing library (nb. Cairo is used by GTK+ anyway, so it's not additional dependency. If you want more, you can even use OpenGL (then you have to use GtkGlExt library).
GTK Tutorial has a chapter dedicated for creating own widgets.
精彩评论