2 * Initial main.c file generated by Glade. Edit as required.
3 * Glade will not overwrite this file.
12 #include "interface.h"
16 #define BOARD_NAME "CNVS_GAMEBOARD"
21 /* border around the board itself */
22 #define BOARD_BORDER 15
23 /* cell size on the board */
28 #define SQUARE_COLOR_1 "white"
29 #define SQUARE_COLOR_2 "grey"
35 static void init_game_board(GtkWidget
*GamazonsMain
);
36 static void draw_a_line(GnomeCanvasGroup
*group
,
37 int x1
, int y1
, int x2
, int y2
, char *color
);
38 void static fill_a_square(GnomeCanvasGroup
*group
,
39 double x1
, double y1
, double x2
, double y2
, char *color
);
40 static void get_square_color(int square
, char *color
);
46 int GameBoard
[BOARD_SIZE
][BOARD_SIZE
];
48 /* Possible square occupants */
59 main (int argc
, char *argv
[])
61 GtkWidget
*GamazonsMain
;
64 bindtextdomain (GETTEXT_PACKAGE
, PACKAGE_LOCALE_DIR
);
65 bind_textdomain_codeset (GETTEXT_PACKAGE
, "UTF-8");
66 textdomain (GETTEXT_PACKAGE
);
69 gnome_program_init (PACKAGE
, VERSION
, LIBGNOMEUI_MODULE
,
71 GNOME_PARAM_APP_DATADIR
, PACKAGE_DATA_DIR
,
75 * The following code was added by Glade to create one of each component
76 * (except popup menus), just so that you see something after building
77 * the project. Delete any components that you don't want shown initially.
79 GamazonsMain
= create_GamazonsMain ();
80 init_game_board(GamazonsMain
);
81 gtk_widget_show (GamazonsMain
);
89 static void init_game_board(GtkWidget
*GamazonsMain
)
93 GtkWidget
*w
= lookup_widget(GamazonsMain
, BOARD_NAME
);
95 canvas
= GNOME_CANVAS(w
);
97 /* set where can the canvas scroll (our usable area) */
98 gnome_canvas_set_scroll_region(canvas
, 0.0, 0.0,
99 BOARD_SIZE
*CELL_SIZE
+ 2*BOARD_BORDER
,
100 BOARD_SIZE
*CELL_SIZE
+ BOARD_BORDER
);
102 /* set the size of the widget */
103 gtk_widget_set_usize(w
,
104 BOARD_SIZE
*CELL_SIZE
+ 2*BOARD_BORDER
,
105 BOARD_SIZE
*CELL_SIZE
+ BOARD_BORDER
);
108 /* initialize pieces */
109 for (i
=0; i
<BOARD_SIZE
; i
++)
111 for (j
=0; j
<BOARD_SIZE
; j
++)
113 GameBoard
[i
][j
] = NOTHING
;
117 GameBoard
[3][9] = WHITE
;
118 GameBoard
[6][9] = WHITE
;
119 GameBoard
[0][6] = WHITE
;
120 GameBoard
[9][6] = WHITE
;
122 GameBoard
[3][0] = BLACK
;
123 GameBoard
[6][0] = BLACK
;
124 GameBoard
[0][3] = BLACK
;
125 GameBoard
[9][3] = BLACK
;
133 draw_a_line(GnomeCanvasGroup
*group
,
134 int x1
, int y1
, int x2
, int y2
, char *color
)
136 GnomeCanvasPoints
*points
;
138 /* allocate a new points array */
139 points
= gnome_canvas_points_new (2);
141 /* fill out the points */
142 points
->coords
[0] = x1
;
143 points
->coords
[1] = y1
;
144 points
->coords
[2] = x2
;
145 points
->coords
[3] = y2
;
147 gnome_canvas_item_new(group
,
148 gnome_canvas_line_get_type(),
151 "width_units", (double)THICKNESS
,
154 /* free the points array */
155 gnome_canvas_points_free(points
);
158 void fill_a_square(GnomeCanvasGroup
*group
,
159 double x1
, double y1
, double x2
, double y2
, char *color
)
162 gnome_canvas_item_new(group
,
163 GNOME_TYPE_CANVAS_RECT
,
168 "outline_color", "black",
170 "width_pixels", (double)THICKNESS
,
175 static void get_square_color(int square
, char *color
)
177 if ((square
% 2) == 0)
178 strcpy(color
, SQUARE_COLOR_1
);
180 strcpy(color
, SQUARE_COLOR_2
);
187 GdkPixbuf
*white_pb
, *black_pb
;
189 GnomeCanvasItem
*image
;
190 GnomeCanvasGroup
*root
= GNOME_CANVAS_GROUP(gnome_canvas_root (GNOME_CANVAS (canvas
)));
193 white_pb
= gdk_pixbuf_new_from_file("/home/yorgasor/Projects/Gamazons/src/white.png", NULL
);
194 if (white_pb
== NULL
)
195 printf("error loading white.png\n");
197 printf("loaded white.png just fine\n");
198 black_pb
= gdk_pixbuf_new_from_file("/home/yorgasor/Projects/Gamazons/src/black.png", NULL
);
199 if (black_pb
== NULL
)
200 printf("error loading black.png\n");
202 /* fill alternate squares */
203 for(i
=0;i
<BOARD_SIZE
;i
++)
205 for(j
=0;j
<BOARD_SIZE
;j
++)
207 get_square_color(i
+j
, color
);
208 fill_a_square(gnome_canvas_root(canvas
),
209 BOARD_BORDER
+ i
*CELL_SIZE
,
210 BOARD_BORDER
+ j
*CELL_SIZE
,
211 BOARD_BORDER
+ i
*(CELL_SIZE
) + CELL_SIZE
,
212 BOARD_BORDER
+ j
*(CELL_SIZE
) + CELL_SIZE
,
214 if (GameBoard
[i
][j
] == WHITE
)
216 printf("Square %dx%d contains a white queen\n",i
,j
);
217 image
= gnome_canvas_item_new (root
,
218 gnome_canvas_pixbuf_get_type (),
219 "x", i
*40.0+15.0, "y", j
*40.0+15.0,
220 "width", 40.0, "height", 40.0,
221 "width_set", TRUE
, "height_set", TRUE
,
225 else if (GameBoard
[i
][j
] == BLACK
)
227 printf("Square %dx%d contains a black queen\n",i
,j
);
228 image
= gnome_canvas_item_new (root
,
229 gnome_canvas_pixbuf_get_type (),
230 "x", i
*40+15.0, "y", j
*40+15.0,
231 "width", 40.0, "height", 40.0,
232 "width_set", TRUE
, "height_set", TRUE
,
240 image = gnome_canvas_item_new (root,
241 gnome_canvas_pixbuf_get_type (),
242 "x", 10.0, "y", 10.0,
243 "width", 40.0, "height", 40.0,
244 "width_set", TRUE, "height_set", TRUE,