1 /*
2 * (c) Copyright 1997, Qun Zhang.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without fee,
6 * provided that the above copyright notice appear in all copies and
7 * that both that copyright notice and this permission notice appear in
8 * supporting documentation, and that the name of Qun Zhang not be used
9 * in advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. Qun Zhang make no
11 * representations about the suitability of this software for any purpose.
12 * It is provided "as is" without express or implied warranty.
13 *
14 * THE ABOVE-NAMED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE ABOVE-NAMED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
18 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 *
22 */
23
24 #ifndef Seat_h
25 #define Seat_h 1
26
27 //## Class: Seat
28 #include <stdio.h>
29 #include <X11/Intrinsic.h>
30 #include <X11/StringDefs.h>
31 #include <X11/Xlib.h>
32 #include <X11/Xmu/Drawing.h>
33 #include <X11/Xutil.h>
34 #include <Xm/Xm.h>
35
36 class Card;
37 class Hands;
38 class Table;
39
40 class Seat
41 {
42 public:
43
44 Seat(Table*);
45 virtual ~Seat();
46
47 int Available() const;
48 void Available(int isAvailable);
49 virtual void ShowCards(Hands *);
50 Table* GetTable() ;
51 virtual void Reset();
52
53 protected:
54 virtual void Initialize( Display*d, int scr, Widget drawArea);
55 virtual int PositionCardX(Card*, int) = 0;
56 virtual int PositionCardY(Card*, int) = 0;
57 void DrawCard(Window, Card*, int x, int y);
58 void DrawCardBack(Window, Card*, int x, int y);
59 void ShowMessage(Window, const char*, int x, int y);
60 Window GetWindow();
61 void MakeCardMaps();
62
63 enum { ROUND_W = 7, ROUND_H = 7,
64 MARGIN_W = 3, MARGIN_H = 3,
65 CARD_MAP_HEIGHT = 123,
66 CARD_MAP_WIDTH = 80,
67 CARD_HEIGHT = 128,
68 CARD_WIDTH = 85
69 } DRAW_CARD_ENUM;
70
71 private:
72
73 Seat();
74 Seat(const Seat &right);
75 const Seat & operator=(const Seat &right);
76 int operator==(const Seat &right) const;
77 int operator!=(const Seat &right) const;
78
79 Pixmap GetCardMap(Card *);
80
81 protected: //## implementation
82
83 int _isAvailable;
84 Table* _table;
85 Bool _cardIsClipped;
86
87 Display * _dpy;
88 int _screen;
89 Widget _drawingArea;
90
91 private: //## implementation
92
93 static int _firstTime;
94 static GC _redgc;
95 static GC _blackgc;
96 static GC _whitegc;
97 static GC _backgc;
98 static GC _cardgc;
99
100 static Pixmap s_map[13], c_map[13];
101 static Pixmap d_map[13], h_map[13];
102 static Pixmap back_map;
103 };
104
105 class PlayerSeat : public Seat
106 {
107 public:
108
109 PlayerSeat(Table* table, int from, int to);
110 virtual ~PlayerSeat();
111
112 protected:
113 virtual int PositionCardX(Card*, int);
114 virtual int PositionCardY(Card*, int);
115
116 private:
117 PlayerSeat();
118 PlayerSeat(const PlayerSeat &right);
119 const PlayerSeat & operator=(const PlayerSeat &right);
120 int operator==(const PlayerSeat &right) const;
121 int operator!=(const PlayerSeat &right) const;
122 private:
123
124 int _from;
125 int _to;
126 };
127
128 class DealerSeat : public Seat
129 {
130 public:
131 DealerSeat(Table* table);
132 virtual ~DealerSeat();
133 void ShowCardsBeforeBet(Hands *);
134 virtual void ShowCards(Hands * hands);
135
136 protected:
137 virtual int PositionCardX(Card*, int);
138 virtual int PositionCardY(Card*, int);
139
140 private:
141 DealerSeat();
142 DealerSeat(const DealerSeat &right);
143 const DealerSeat & operator=(const DealerSeat &right);
144 int operator==(const DealerSeat &right) const;
145 int operator!=(const DealerSeat &right) const;
146
147 GC _msggc;
148 };
149
150 // Class Seat
Available()151 inline int Seat::Available() const
152 {
153 return _isAvailable;
154 }
155
Available(int isAvailable)156 inline void Seat::Available(int isAvailable)
157 {
158 _isAvailable = isAvailable;
159 }
160
GetTable()161 inline Table* Seat::GetTable() { return _table;}
162
GetWindow()163 inline Window Seat::GetWindow() { return XtWindow(_drawingArea); }
164
ShowMessage(Window w,const char * msg,int x,int y)165 inline void Seat::ShowMessage(Window w, const char* msg , int x, int y)
166 {
167 XDrawString(_dpy, w, _redgc, x, y, msg, strlen(msg));
168 }
169 #endif
170