File: tile.c

package info (click to toggle)
gnome-mines 1%3A3.22.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 18,436 kB
  • ctags: 753
  • sloc: ansic: 9,582; sh: 1,237; makefile: 156; xml: 61
file content (479 lines) | stat: -rw-r--r-- 16,174 bytes parent folder | download
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
/* tile.c generated by valac 0.34.2, the Vala compiler
 * generated from tile.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <cairo.h>
#include <gdk/gdk.h>


#define TYPE_TILE (tile_get_type ())
#define TILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TILE, Tile))
#define TILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TILE, TileClass))
#define IS_TILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TILE))
#define IS_TILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TILE))
#define TILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TILE, TileClass))

typedef struct _Tile Tile;
typedef struct _TileClass TileClass;
typedef struct _TilePrivate TilePrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _Block2Data Block2Data;

struct _Tile {
	GtkButton parent_instance;
	TilePrivate * priv;
};

struct _TileClass {
	GtkButtonClass parent_class;
};

struct _TilePrivate {
	gint _row;
	gint _column;
	GtkImage* scaling_image;
};

struct _Block2Data {
	int _ref_count_;
	Tile* self;
	gint prow;
	gint pcol;
};


static gpointer tile_parent_class = NULL;
static gchar** tile_IMAGE_CLASSES;
static gint tile_IMAGE_CLASSES_length1;
static gchar** tile_IMAGE_CLASSES = NULL;
static gint tile_IMAGE_CLASSES_length1 = 0;
static gint _tile_IMAGE_CLASSES_size_ = 0;

GType tile_get_type (void) G_GNUC_CONST;
#define TILE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_TILE, TilePrivate))
enum  {
	TILE_DUMMY_PROPERTY,
	TILE_ROW,
	TILE_COLUMN
};
void tile_refresh_icon (Tile* self);
Tile* tile_new (gint prow, gint pcol);
Tile* tile_construct (GType object_type, gint prow, gint pcol);
static Block2Data* block2_data_ref (Block2Data* _data2_);
static void block2_data_unref (void * _userdata_);
void tile_add_class (Tile* self, const gchar* style_class);
static void __lambda4_ (Tile* self, GtkAllocation* allocation);
static void ___lambda4__gtk_widget_size_allocate (GtkWidget* _sender, GtkAllocation* allocation, gpointer self);
static gboolean __lambda5_ (Block2Data* _data2_, GdkEventButton* event);
static gboolean ___lambda5__gtk_widget_button_press_event (GtkWidget* _sender, GdkEventButton* event, gpointer self);
static gboolean __lambda6_ (Block2Data* _data2_, GdkEventButton* event);
static gboolean ___lambda6__gtk_widget_button_release_event (GtkWidget* _sender, GdkEventButton* event, gpointer self);
static gboolean _vala_string_array_contains (gchar** stack, int stack_length, gchar* needle);
void tile_remove_class (Tile* self, const gchar* style_class);
gint tile_get_row (Tile* self);
gint tile_get_column (Tile* self);
static void g_cclosure_user_marshal_VOID__INT_INT (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data);
static void g_cclosure_user_marshal_VOID__INT_INT_BOXED (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data);
static void tile_finalize (GObject* obj);
static void _vala_tile_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);


void tile_refresh_icon (Tile* self) {
	gchar* name = NULL;
	GtkIconSize size = 0;
	GtkImage* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	GtkIconSize _tmp2_ = 0;
	gchar* _tmp3_ = NULL;
	GtkImage* _tmp4_ = NULL;
	GtkImage* _tmp5_ = NULL;
	GtkImage* _tmp6_ = NULL;
	gint _tmp7_ = 0;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->scaling_image;
	gtk_image_get_icon_name (_tmp0_, &_tmp1_, &_tmp2_);
	_g_free0 (name);
	_tmp3_ = g_strdup (_tmp1_);
	name = _tmp3_;
	size = _tmp2_;
	_tmp4_ = self->priv->scaling_image;
	gtk_image_clear (_tmp4_);
	_tmp5_ = self->priv->scaling_image;
	gtk_image_set_from_icon_name (_tmp5_, name, size);
	_tmp6_ = self->priv->scaling_image;
	_tmp7_ = gtk_widget_get_allocated_height ((GtkWidget*) self);
	gtk_image_set_pixel_size (_tmp6_, (_tmp7_ / 3) * 2);
	_g_free0 (name);
}


static Block2Data* block2_data_ref (Block2Data* _data2_) {
	g_atomic_int_inc (&_data2_->_ref_count_);
	return _data2_;
}


static void block2_data_unref (void * _userdata_) {
	Block2Data* _data2_;
	_data2_ = (Block2Data*) _userdata_;
	if (g_atomic_int_dec_and_test (&_data2_->_ref_count_)) {
		Tile* self;
		self = _data2_->self;
		_g_object_unref0 (self);
		g_slice_free (Block2Data, _data2_);
	}
}


static void __lambda4_ (Tile* self, GtkAllocation* allocation) {
	GtkImage* _tmp0_ = NULL;
	GtkAllocation _tmp1_ = {0};
	gint _tmp2_ = 0;
	g_return_if_fail (allocation != NULL);
	_tmp0_ = self->priv->scaling_image;
	_tmp1_ = *allocation;
	_tmp2_ = _tmp1_.height;
	gtk_image_set_pixel_size (_tmp0_, (_tmp2_ / 3) * 2);
}


static void ___lambda4__gtk_widget_size_allocate (GtkWidget* _sender, GtkAllocation* allocation, gpointer self) {
	__lambda4_ ((Tile*) self, allocation);
}


static gboolean __lambda5_ (Block2Data* _data2_, GdkEventButton* event) {
	Tile* self;
	gboolean result = FALSE;
	GdkEventButton* _tmp0_ = NULL;
	GdkDevice* _tmp1_ = NULL;
	GdkEventButton* _tmp2_ = NULL;
	guint32 _tmp3_ = 0U;
	gint _tmp4_ = 0;
	gint _tmp5_ = 0;
	GdkEventButton* _tmp6_ = NULL;
	self = _data2_->self;
	g_return_val_if_fail (event != NULL, FALSE);
	_tmp0_ = event;
	_tmp1_ = _tmp0_->device;
	_tmp2_ = event;
	_tmp3_ = _tmp2_->time;
	gdk_device_ungrab (_tmp1_, _tmp3_);
	_tmp4_ = _data2_->prow;
	_tmp5_ = _data2_->pcol;
	_tmp6_ = event;
	g_signal_emit_by_name (self, "tile-pressed", _tmp4_, _tmp5_, _tmp6_);
	result = FALSE;
	return result;
}


static gboolean ___lambda5__gtk_widget_button_press_event (GtkWidget* _sender, GdkEventButton* event, gpointer self) {
	gboolean result;
	result = __lambda5_ (self, event);
	return result;
}


static gboolean __lambda6_ (Block2Data* _data2_, GdkEventButton* event) {
	Tile* self;
	gboolean result = FALSE;
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	GdkEventButton* _tmp2_ = NULL;
	self = _data2_->self;
	g_return_val_if_fail (event != NULL, FALSE);
	_tmp0_ = _data2_->prow;
	_tmp1_ = _data2_->pcol;
	_tmp2_ = event;
	g_signal_emit_by_name (self, "tile-released", _tmp0_, _tmp1_, _tmp2_);
	result = FALSE;
	return result;
}


static gboolean ___lambda6__gtk_widget_button_release_event (GtkWidget* _sender, GdkEventButton* event, gpointer self) {
	gboolean result;
	result = __lambda6_ (self, event);
	return result;
}


Tile* tile_construct (GType object_type, gint prow, gint pcol) {
	Tile * self = NULL;
	Block2Data* _data2_;
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	gint _tmp3_ = 0;
	GtkImage* _tmp4_ = NULL;
	GtkImage* _tmp5_ = NULL;
	_data2_ = g_slice_new0 (Block2Data);
	_data2_->_ref_count_ = 1;
	_tmp0_ = prow;
	_data2_->prow = _tmp0_;
	_tmp1_ = pcol;
	_data2_->pcol = _tmp1_;
	self = (Tile*) g_object_new (object_type, NULL);
	_data2_->self = g_object_ref (self);
	_tmp2_ = _data2_->prow;
	self->priv->_row = _tmp2_;
	_tmp3_ = _data2_->pcol;
	self->priv->_column = _tmp3_;
	_tmp4_ = (GtkImage*) gtk_image_new ();
	g_object_ref_sink (_tmp4_);
	_g_object_unref0 (self->priv->scaling_image);
	self->priv->scaling_image = _tmp4_;
	g_object_set ((GtkWidget*) self, "can-focus", FALSE, NULL);
	tile_add_class (self, "tile");
	_tmp5_ = self->priv->scaling_image;
	gtk_button_set_image ((GtkButton*) self, (GtkWidget*) _tmp5_);
	g_signal_connect_object ((GtkWidget*) self, "size-allocate", (GCallback) ___lambda4__gtk_widget_size_allocate, self, 0);
	g_signal_connect_data ((GtkWidget*) self, "button-press-event", (GCallback) ___lambda5__gtk_widget_button_press_event, block2_data_ref (_data2_), (GClosureNotify) block2_data_unref, 0);
	g_signal_connect_data ((GtkWidget*) self, "button-release-event", (GCallback) ___lambda6__gtk_widget_button_release_event, block2_data_ref (_data2_), (GClosureNotify) block2_data_unref, 0);
	block2_data_unref (_data2_);
	_data2_ = NULL;
	return self;
}


Tile* tile_new (gint prow, gint pcol) {
	return tile_construct (TYPE_TILE, prow, pcol);
}


static gboolean _vala_string_array_contains (gchar** stack, int stack_length, gchar* needle) {
	int i;
	for (i = 0; i < stack_length; i++) {
		if (g_strcmp0 (stack[i], needle) == 0) {
			return TRUE;
		}
	}
	return FALSE;
}


void tile_add_class (Tile* self, const gchar* style_class) {
	GtkStyleContext* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar** _tmp3_ = NULL;
	gint _tmp3__length1 = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (style_class != NULL);
	_tmp0_ = gtk_widget_get_style_context ((GtkWidget*) self);
	_tmp1_ = style_class;
	gtk_style_context_add_class (_tmp0_, _tmp1_);
	_tmp2_ = style_class;
	_tmp3_ = tile_IMAGE_CLASSES;
	_tmp3__length1 = tile_IMAGE_CLASSES_length1;
	if (_vala_string_array_contains (_tmp3_, _tmp3__length1, _tmp2_)) {
		GtkImage* _tmp4_ = NULL;
		const gchar* _tmp5_ = NULL;
		GtkImage* _tmp6_ = NULL;
		gint _tmp7_ = 0;
		_tmp4_ = self->priv->scaling_image;
		_tmp5_ = style_class;
		gtk_image_set_from_icon_name (_tmp4_, _tmp5_, GTK_ICON_SIZE_DND);
		_tmp6_ = self->priv->scaling_image;
		_tmp7_ = gtk_widget_get_allocated_height ((GtkWidget*) self);
		gtk_image_set_pixel_size (_tmp6_, (_tmp7_ / 3) * 2);
	}
}


void tile_remove_class (Tile* self, const gchar* style_class) {
	GtkStyleContext* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	gchar** _tmp3_ = NULL;
	gint _tmp3__length1 = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (style_class != NULL);
	_tmp0_ = gtk_widget_get_style_context ((GtkWidget*) self);
	_tmp1_ = style_class;
	gtk_style_context_remove_class (_tmp0_, _tmp1_);
	_tmp2_ = style_class;
	_tmp3_ = tile_IMAGE_CLASSES;
	_tmp3__length1 = tile_IMAGE_CLASSES_length1;
	if (_vala_string_array_contains (_tmp3_, _tmp3__length1, _tmp2_)) {
		GtkImage* _tmp4_ = NULL;
		GtkImage* _tmp5_ = NULL;
		_tmp4_ = (GtkImage*) gtk_image_new ();
		g_object_ref_sink (_tmp4_);
		_g_object_unref0 (self->priv->scaling_image);
		self->priv->scaling_image = _tmp4_;
		_tmp5_ = self->priv->scaling_image;
		gtk_button_set_image ((GtkButton*) self, (GtkWidget*) _tmp5_);
	}
}


gint tile_get_row (Tile* self) {
	gint result;
	gint _tmp0_ = 0;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->_row;
	result = _tmp0_;
	return result;
}


gint tile_get_column (Tile* self) {
	gint result;
	gint _tmp0_ = 0;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->_column;
	result = _tmp0_;
	return result;
}


static void g_cclosure_user_marshal_VOID__INT_INT (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data) {
	typedef void (*GMarshalFunc_VOID__INT_INT) (gpointer data1, gint arg_1, gint arg_2, gpointer data2);
	register GMarshalFunc_VOID__INT_INT callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 3);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__INT_INT) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_int (param_values + 1), g_value_get_int (param_values + 2), data2);
}


static void g_cclosure_user_marshal_VOID__INT_INT_BOXED (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data) {
	typedef void (*GMarshalFunc_VOID__INT_INT_BOXED) (gpointer data1, gint arg_1, gint arg_2, gpointer arg_3, gpointer data2);
	register GMarshalFunc_VOID__INT_INT_BOXED callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 4);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__INT_INT_BOXED) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_int (param_values + 1), g_value_get_int (param_values + 2), g_value_get_boxed (param_values + 3), data2);
}


static void tile_class_init (TileClass * klass) {
	gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	gchar* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	gchar* _tmp8_ = NULL;
	gchar* _tmp9_ = NULL;
	gchar* _tmp10_ = NULL;
	gchar* _tmp11_ = NULL;
	gchar* _tmp12_ = NULL;
	gchar* _tmp13_ = NULL;
	gchar** _tmp14_ = NULL;
	tile_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (TilePrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_tile_get_property;
	G_OBJECT_CLASS (klass)->finalize = tile_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), TILE_ROW, g_param_spec_int ("row", "row", "row", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), TILE_COLUMN, g_param_spec_int ("column", "column", "column", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
	g_signal_new ("tile_mouse_over", TYPE_TILE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__INT_INT, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
	g_signal_new ("tile_pressed", TYPE_TILE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__INT_INT_BOXED, G_TYPE_NONE, 3, G_TYPE_INT, G_TYPE_INT, gdk_event_get_type ());
	g_signal_new ("tile_released", TYPE_TILE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__INT_INT_BOXED, G_TYPE_NONE, 3, G_TYPE_INT, G_TYPE_INT, gdk_event_get_type ());
	_tmp0_ = g_strdup ("mine");
	_tmp1_ = g_strdup ("flag");
	_tmp2_ = g_strdup ("incorrect");
	_tmp3_ = g_strdup ("maybe");
	_tmp4_ = g_strdup ("overmine");
	_tmp5_ = g_strdup ("exploded");
	_tmp6_ = g_strdup ("1mines");
	_tmp7_ = g_strdup ("2mines");
	_tmp8_ = g_strdup ("3mines");
	_tmp9_ = g_strdup ("4mines");
	_tmp10_ = g_strdup ("5mines");
	_tmp11_ = g_strdup ("6mines");
	_tmp12_ = g_strdup ("7mines");
	_tmp13_ = g_strdup ("8mines");
	_tmp14_ = g_new0 (gchar*, 14 + 1);
	_tmp14_[0] = _tmp0_;
	_tmp14_[1] = _tmp1_;
	_tmp14_[2] = _tmp2_;
	_tmp14_[3] = _tmp3_;
	_tmp14_[4] = _tmp4_;
	_tmp14_[5] = _tmp5_;
	_tmp14_[6] = _tmp6_;
	_tmp14_[7] = _tmp7_;
	_tmp14_[8] = _tmp8_;
	_tmp14_[9] = _tmp9_;
	_tmp14_[10] = _tmp10_;
	_tmp14_[11] = _tmp11_;
	_tmp14_[12] = _tmp12_;
	_tmp14_[13] = _tmp13_;
	tile_IMAGE_CLASSES = _tmp14_;
	tile_IMAGE_CLASSES_length1 = 14;
}


static void tile_instance_init (Tile * self) {
	self->priv = TILE_GET_PRIVATE (self);
}


static void tile_finalize (GObject* obj) {
	Tile * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_TILE, Tile);
	_g_object_unref0 (self->priv->scaling_image);
	G_OBJECT_CLASS (tile_parent_class)->finalize (obj);
}


GType tile_get_type (void) {
	static volatile gsize tile_type_id__volatile = 0;
	if (g_once_init_enter (&tile_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (TileClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) tile_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Tile), 0, (GInstanceInitFunc) tile_instance_init, NULL };
		GType tile_type_id;
		tile_type_id = g_type_register_static (gtk_button_get_type (), "Tile", &g_define_type_info, 0);
		g_once_init_leave (&tile_type_id__volatile, tile_type_id);
	}
	return tile_type_id__volatile;
}


static void _vala_tile_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	Tile * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_TILE, Tile);
	switch (property_id) {
		case TILE_ROW:
		g_value_set_int (value, tile_get_row (self));
		break;
		case TILE_COLUMN:
		g_value_set_int (value, tile_get_column (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}