File: MainDeck.cxx

package info (click to toggle)
oonsoo 1.2-8
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,604 kB
  • ctags: 422
  • sloc: cpp: 24,373; makefile: 82
file content (210 lines) | stat: -rw-r--r-- 6,337 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
///////////////////////////////////////////////////////////////////////////////
// $Id: MainDeck.cxx,v 1.3 2000/01/10 23:28:43 bwmott Exp $
///////////////////////////////////////////////////////////////////////////////
//
// MainDeck.hxx - Main oonsoo deck of cards (Dealer's deck)
//
//
// Bradford W. Mott
// Copyright (C) 1994
// December 13,1994
//
///////////////////////////////////////////////////////////////////////////////
// $Log: MainDeck.cxx,v $
// Revision 1.3  2000/01/10 23:28:43  bwmott
// Modified pixmap operations to take the display depth into account and
// changed the order of the cards
//
// Revision 1.2  1996/01/06 05:11:46  bwmott
// Changed all NULLs to 0
//
// Revision 1.1  1995/01/08 06:44:41  bmott
// Initial revision
//
///////////////////////////////////////////////////////////////////////////////

#include "UIApplication.hxx"
#include "Sprite.hxx"
#include "SpriteCollection.hxx"
#include "Card.hxx"
#include "MainDeck.hxx"
#include "Command.hxx"

// Structure to describe standard cards
typedef struct {
  int suite;
  int priority;
  char* name;
} StandardCard;

// Standard deck of oonsoo cards 
static StandardCard standardDeckOfCards[] = {
  { 12,  2,  "BlueStarOne" },
  { 12,  2,  "BlueStarTwo" },
  { 12,  3,  "BlueStarThree" },
  { 12,  4,  "BlueStarFour" },
  { 11,  1,  "HairOne" },
  { 11,  2,  "HairTwo" },
  { 11,  3,  "HairThree" },
  { 11,  4,  "HairFour" },
  { 10,  2,  "LeavesOne" },
  { 10,  2,  "LeavesTwo" },
  { 10,  3,  "LeavesThree" },
  { 10,  4,  "LeavesFour" },
  {  9,  2,  "MumOne" },
  {  9,  2,  "MumTwo" },
  {  9,  3,  "MumThree" },
  {  9,  4,  "MumFour" },
  {  8,  2,  "MoonOne" },
  {  8,  2,  "MoonTwo" },
  {  8,  3,  "MoonThree" },
  {  8,  4,  "MoonFour" },
  {  7,  2,  "RedBushOne" },
  {  7,  2,  "RedBushTwo" },
  {  7,  3,  "RedBushThree" },
  {  7,  4,  "RedBushFour" },
  {  6,  2,  "RoseOne" },
  {  6,  2,  "RoseTwo" },
  {  6,  3,  "RoseThree" },
  {  6,  4,  "RoseFour" },
  {  5,  2,  "LilyOne" },
  {  5,  2,  "LilyTwo" },
  {  5,  3,  "LilyThree" },
  {  5,  4,  "LilyFour" },
  {  4,  2,  "BushOne" },     
  {  4,  2,  "BushTwo" },
  {  4,  3,  "BushThree" },  
  {  4,  4,  "BushFour" },
  {  3,  2,  "AzaleaOne" },
  {  3,  2,  "AzaleaTwo" },
  {  3,  3,  "AzaleaThree" },
  {  3,  4,  "AzaleaFour" },
  {  2,  2,  "DaisyOne" },
  {  2,  2,  "DaisyTwo" },
  {  2,  3,  "DaisyThree" },
  {  2,  4,  "DaisyFour" },
  {  1,  2,  "HillOne" },
  {  1,  2,  "HillTwo" },
  {  1,  3,  "HillThree" },
  {  1,  4,  "HillFour" }
};

///////////////////////////////////////////////////////////////////////////////
// Construct a complete deck of oonsoo cards
///////////////////////////////////////////////////////////////////////////////
MainDeck::MainDeck(ContainerWidget* parent, const char *const widgetName,
    int x, int y, int width, int maxHeight, 
    SpriteCollection* sprites, Command* command)
    : Deck(parent, widgetName, x, y, width, maxHeight, sprites),
      myCommand(command)
{
  // Create each of the cards
  for(int t=0; t < (sizeof(standardDeckOfCards)/sizeof(StandardCard)); ++t)
  {
    Sprite* face = sprites->getByName(standardDeckOfCards[t].name);

    Card* card = new Card(face, standardDeckOfCards[t].suite,
        standardDeckOfCards[t].priority, FaceDown);

    myListOfCards.append(card);
  }

  // Update my view
  updateView();
}

///////////////////////////////////////////////////////////////////////////////
// Destructor
///////////////////////////////////////////////////////////////////////////////
MainDeck::~MainDeck()
{ 
  delete myCommand;
}

///////////////////////////////////////////////////////////////////////////////
// Update graphical view of myself
///////////////////////////////////////////////////////////////////////////////
void MainDeck::updateView()
{
  Pixmap pixmap;

  Sprite* back = mySprites->getByName("StandardBack");
  Sprite* emptyDeck = mySprites->getByName("EmptyDeck");

  int numberOfCards = myListOfCards.size();
  int cardWidth = back->width();
  int cardHeight = back->height();
  int drawingAreaHeight;
  int drawingAreaWidth;


  // See if I have any cards
  if(numberOfCards > 0)
  {
    int cardOffset;

    cardOffset = (myMaximumHeight - cardHeight) / 
        ((sizeof(standardDeckOfCards) / sizeof(StandardCard)) - 1); 
    drawingAreaHeight = cardHeight + (numberOfCards-1) * cardOffset;
    drawingAreaWidth = cardWidth;

    // Build pixmap to hold my view
    pixmap = XCreatePixmap(application->display(), myWindow,
        drawingAreaWidth, drawingAreaHeight, application->depth());

    int pixmapOffset = 0;
    for(Card* card = myListOfCards.first(); card != (Card*)0 ;
        card = myListOfCards.next())
    {
      Sprite* sprite;

      if(card != myListOfCards.tail())
        XPutImage(application->display(), pixmap, application->gc(),
            back->image(), 0, 0, 0, pixmapOffset, 
            back->width(), cardOffset);
      else
        XPutImage(application->display(), pixmap, application->gc(),
            back->image(), 0, 0, 0, pixmapOffset, 
            back->width(), back->height());

      pixmapOffset += cardOffset;
    }
  }
  else
  {
    Sprite* sprite = emptyDeck;
    drawingAreaWidth = sprite->width();
    drawingAreaHeight = sprite->height();

    // Build pixmap to hold my view
    pixmap = XCreatePixmap(application->display(), myWindow, 
        drawingAreaWidth, drawingAreaHeight, application->depth());
    
    XPutImage(application->display(), pixmap, application->gc(), 
        sprite->image(), 0, 0, 0, 0, sprite->width(), sprite->height());
  }

  // Install the pixmap on my drawing area
  XSetWindowBackgroundPixmap(application->display(), myWindow, pixmap);

  // Make sure the window refreshes
  XClearWindow(application->display(), myWindow);

  // Resize the window to fit the pixmap
  resize(drawingAreaWidth, drawingAreaHeight);

  // Free the pixmap
  XFreePixmap(application->display(), pixmap);
}

///////////////////////////////////////////////////////////////////////////////
// Called whenever an event arrives for me (I need to override the default)
///////////////////////////////////////////////////////////////////////////////
void MainDeck::handleEvent(XEvent* event)
{
  if ((event->type == ButtonPress) && (event->xbutton.button == Button1))
  {
    myCommand->execute(0);
  }
}