1 #include "config.h"
2 #include "game.h"
3 #include <gtk/gtk.h>
4 #include <string.h>
5 #include <glib.h>
6
7 #include "game-resources.h"
8
9 static void game_resources_init(GTypeInstance * instance,
10 gpointer g_class);
11
12 /* Register the class */
game_resources_get_type(void)13 GType game_resources_get_type(void)
14 {
15 static GType gr_type = 0;
16
17 if (!gr_type) {
18 static const GTypeInfo gr_info = {
19 sizeof(GameResourcesClass),
20 NULL, /* base_init */
21 NULL, /* base_finalize */
22 NULL, /* class init */
23 NULL, /* class_finalize */
24 NULL, /* class_data */
25 sizeof(GameResources),
26 0,
27 game_resources_init,
28 NULL
29 };
30 gr_type =
31 g_type_register_static(GTK_TYPE_GRID, "GameResources",
32 &gr_info, 0);
33 }
34 return gr_type;
35 }
36
37 /* Build the composite widget */
game_resources_init(GTypeInstance * instance,G_GNUC_UNUSED gpointer g_class)38 static void game_resources_init(GTypeInstance * instance,
39 G_GNUC_UNUSED gpointer g_class)
40 {
41 GtkWidget *label;
42 GtkWidget *spin;
43 GtkAdjustment *adjustment;
44 GameResources *gr = GAMERESOURCES(instance);
45
46 gtk_grid_set_row_spacing(GTK_GRID(gr), 3);
47 gtk_grid_set_column_spacing(GTK_GRID(gr), 5);
48 gtk_grid_set_column_homogeneous(GTK_GRID(gr), TRUE);
49
50 label = gtk_label_new(_("Resource count"));
51 gtk_label_set_xalign(GTK_LABEL(label), 0.0);
52 gtk_grid_attach(GTK_GRID(gr), label, 0, 0, 1, 1);
53
54 adjustment =
55 GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 100, 1, 5, 0));
56 spin = gtk_spin_button_new(GTK_ADJUSTMENT(adjustment), 1, 0);
57 gtk_entry_set_alignment(GTK_ENTRY(spin), 1.0);
58 gtk_grid_attach(GTK_GRID(gr), spin, 1, 0, 1, 1);
59 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(spin), TRUE);
60 gr->num_resources = GTK_SPIN_BUTTON(spin);
61 }
62
63 /* Create a new instance of the widget */
game_resources_new(void)64 GtkWidget *game_resources_new(void)
65 {
66 return GTK_WIDGET(g_object_new(game_resources_get_type(), NULL));
67 }
68
game_resources_set_num_resources(GameResources * gr,gint num)69 void game_resources_set_num_resources(GameResources * gr, gint num)
70 {
71 gtk_spin_button_set_value(gr->num_resources, num);
72 }
73
game_resources_get_num_resources(GameResources * gr)74 gint game_resources_get_num_resources(GameResources * gr)
75 {
76 return gtk_spin_button_get_value_as_int(gr->num_resources);
77 }
78