1 /*
2 
3     Euchre - a free as in freedom and as in beer version of the
4              euchre card game
5 
6     Copyright 2002 C Nathan Buckles (nbuckles@bigfoot.com)
7 
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12 
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17 
18     You should have received a copy of the GNU General Public License
19     along with this program; if not, write to the Free Software
20     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 
22 */
23 
24 #ifdef HAVE_CONFIG_H
25 #  include <config.h>
26 #endif
27 
28 #include <stdio.h>
29 #include <gtk/gtk.h>
30 
31 #include <Options.hpp>
32 #include <pixmaps.hpp>
33 
34 extern "C" {
35 #include "interface.h"
36 }
37 
38 #include "support.hpp"
39 #include "globals.hpp"
40 
41 /* local functions */
42 static void create_pixmaps();
43 static void create_cards(GtkWidget*);
44 static void create_bid_pixmaps(GtkWidget*);
45 static void create_markers(GtkWidget*);
46 
47 int
main(int argc,char * argv[])48 main (int argc, char *argv[])
49 {
50 
51 #ifdef ENABLE_NLS
52   bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
53   textdomain (PACKAGE);
54 #endif
55 
56   gtk_init(&argc, &argv);
57 
58   /* create the top level windows */
59   mainwin    = create_mainwin();
60   prefdiag   = create_Preferences();
61   prevdiag   = create_prevtrick();
62 
63   create_pixmaps();
64   create_cards(mainwin);
65   create_bid_pixmaps(mainwin);
66   create_markers(mainwin);
67 
68   GuiOptions::set(new GuiOptions());
69   GuiOptions::get()->init();
70 
71   theGame = new GuiGame();
72   theGame->setOptions();
73 
74   gtk_widget_show(mainwin);
75   gtk_main ();
76   return 0;
77 }
78 
create_pixmaps()79 static void create_pixmaps() {
80   GdkColormap* gdk_c;
81   GtkWidget*   gtk_w;
82 
83   char widget_name[256];
84   for (int i = 0; i < NUM_CARD_BACKS; i++) {
85     sprintf(widget_name, "cardback%d_pixmap", i);
86     gtk_w = lookup_widget(prefdiag, widget_name);
87 
88     gdk_c = gtk_widget_get_colormap(gtk_w);
89 
90     cardbackSelectPixmaps[i] =
91       gdk_pixmap_colormap_create_from_xpm_d(NULL, gdk_c,
92 					    &(cardbackSelectBitmaps[i]),
93 					    NULL, (gchar**) card_back_pixmap[i]);
94     gtk_pixmap_set(GTK_PIXMAP(gtk_w), cardbackSelectPixmaps[i],
95 		   cardbackSelectBitmaps[i]);
96     gdk_pixmap_unref(cardbackSelectPixmaps[i]);
97     gdk_bitmap_unref(cardbackSelectBitmaps[i]);
98   }
99 }
100 
create_cards(GtkWidget * win)101 static void create_cards(GtkWidget* win) {
102   int n, s;
103   char pixmap_name[100];
104 
105   for (n = 0; n < (Card::Ace+1); n++) {
106     for (s = 0; s < (Card::Spades+1); s++) {
107       sprintf(pixmap_name, "card_%d_%d.xpm", n, s);
108       cardPixmaps[n][s] = create_pixmap_d(win, (gchar**) card_pixmap_array[n][s]);
109 
110       gtk_widget_ref(cardPixmaps[n][s]);
111       gtk_object_set_data_full(GTK_OBJECT (win),
112 			       pixmap_name, cardPixmaps[n][s],
113 			       (GtkDestroyNotify) gtk_widget_unref);
114       gtk_widget_show(cardPixmaps[n][s]);
115     }
116   }
117 }
118 
create_bid_pixmaps(GtkWidget * win)119 static void create_bid_pixmaps(GtkWidget* win) {
120   int  s;
121   char pixmap_name[100];
122 
123   /* create each little suit pixmap */
124   for (s = 0; s < (Card::Spades+1); s++) {
125     sprintf(pixmap_name, "bid_%d.xpm", s);
126     bidSuitPixmaps[s] = create_pixmap_d(win, (gchar**) suit_pixmap[s]);
127 
128     gtk_widget_ref(bidSuitPixmaps[s]);
129     gtk_object_set_data_full(GTK_OBJECT(win),
130 			     pixmap_name, bidSuitPixmaps[s],
131 			     (GtkDestroyNotify) gtk_widget_unref);
132     gtk_widget_show(bidSuitPixmaps[s]);
133   }
134 
135   /* create the loner and team bid pixmaps */
136   for (s = 0; s < 2; s++) {
137     bidCallPixmaps[s] = create_pixmap_d(win, (gchar**) bid_pixmap[s]);
138 
139     gtk_widget_ref(bidCallPixmaps[s]);
140     gtk_widget_show(bidCallPixmaps[s]);
141   }
142 
143   /* create empty pixmaps to use as pads */
144   for (s = 0; s < Common::PLAYERS_PER_GAME; s++) {
145     bidEmptyPixmaps[s] = create_pixmap_d(win, (gchar**) bid_empty_pixmap);
146 
147     gtk_widget_ref(bidEmptyPixmaps[s]);
148     gtk_widget_show(bidEmptyPixmaps[s]);
149 
150     bidSuitEmptyPixmaps[s] = create_pixmap_d(win, (gchar**) bid_empty_pixmap);
151 
152     gtk_widget_ref(bidSuitEmptyPixmaps[s]);
153     gtk_widget_show(bidSuitEmptyPixmaps[s]);
154   }
155 
156   /* create pixmaps to put onto the bid buttons */
157   GdkColormap* gdk_c;
158   GdkPixmap*   gdk_p;
159   GdkBitmap*   gdk_m;
160   GtkWidget*   gtk_w;
161   char widget_name[256];
162 
163   for (s = 0; s < (Card::Spades+1); s++) {
164     sprintf(widget_name, "bid_pixmap_%d", s);
165     gtk_w = lookup_widget(win, widget_name);
166 
167     gdk_c = gtk_widget_get_colormap(gtk_w);
168     gdk_p = gdk_pixmap_colormap_create_from_xpm_d(NULL, gdk_c, &gdk_m,
169 						  NULL, (gchar**) suit_pixmap[s]);
170 
171     gtk_pixmap_set(GTK_PIXMAP(gtk_w), gdk_p, gdk_m);
172     gdk_pixmap_unref(gdk_p);
173     gdk_bitmap_unref(gdk_m);
174   }
175 }
176 
create_markers(GtkWidget * win)177 void create_markers(GtkWidget* win) {
178   for (int p = 0; p < Common::PLAYERS_PER_GAME; p++) {
179     passMarkers[p] = create_pixmap_d(win, (gchar**) pass_marker_pixmap);
180 
181     gtk_widget_ref(passMarkers[p]);
182     gtk_object_set_data_full(GTK_OBJECT(win),
183 			     "pass_marker", passMarkers[p],
184 			     (GtkDestroyNotify) gtk_widget_unref);
185     gtk_widget_show(passMarkers[p]);
186 
187     emptyMarkers[p] = create_pixmap_d(win, (gchar**) empty_marker_pixmap);
188 
189     gtk_widget_ref(emptyMarkers[p]);
190     gtk_object_set_data_full(GTK_OBJECT(win),
191 			     "empty_marker", emptyMarkers[p],
192 			     (GtkDestroyNotify) gtk_widget_unref);
193     gtk_widget_show(emptyMarkers[p]);
194 
195   }
196 
197   GtkWidget* ttt = lookup_widget(win, "marker_table");
198 
199   gtk_table_attach(GTK_TABLE(ttt), emptyMarkers[0],
200 		   1, 2, 0, 1,
201 		   (GtkAttachOptions) (GTK_FILL),
202 		   (GtkAttachOptions) (GTK_FILL), 0, 0);
203   gtk_table_attach(GTK_TABLE(ttt), emptyMarkers[1],
204 		   2, 3, 1, 2,
205 		   (GtkAttachOptions) (GTK_FILL),
206 		   (GtkAttachOptions) (GTK_FILL), 0, 0);
207   gtk_table_attach(GTK_TABLE(ttt), emptyMarkers[2],
208 		   1, 2, 2, 3,
209 		   (GtkAttachOptions) (GTK_FILL),
210 		   (GtkAttachOptions) (GTK_FILL), 0, 0);
211   gtk_table_attach(GTK_TABLE(ttt), emptyMarkers[3],
212 		   0, 1, 1, 2,
213 		   (GtkAttachOptions) (GTK_FILL),
214 		   (GtkAttachOptions) (GTK_FILL), 0, 0);
215 }
216