1
/* chess-view-3d.c generated by valac 0.12.0, the Vala compiler
2
* generated from chess-view-3d.vala, do not modify */
6
#include <glib-object.h>
18
#include <X11/Xatom.h>
19
#include <X11/Xutil.h>
20
#include <X11/Xregion.h>
24
#include <gdk-pixbuf/gdk-pixdata.h>
27
#define TYPE_CHESS_VIEW (chess_view_get_type ())
28
#define CHESS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_VIEW, ChessView))
29
#define CHESS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_VIEW, ChessViewClass))
30
#define IS_CHESS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_VIEW))
31
#define IS_CHESS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_VIEW))
32
#define CHESS_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_VIEW, ChessViewClass))
34
typedef struct _ChessView ChessView;
35
typedef struct _ChessViewClass ChessViewClass;
36
typedef struct _ChessViewPrivate ChessViewPrivate;
38
#define TYPE_CHESS_VIEW3_D (chess_view3_d_get_type ())
39
#define CHESS_VIEW3_D(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_VIEW3_D, ChessView3D))
40
#define CHESS_VIEW3_D_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_VIEW3_D, ChessView3DClass))
41
#define IS_CHESS_VIEW3_D(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_VIEW3_D))
42
#define IS_CHESS_VIEW3_D_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_VIEW3_D))
43
#define CHESS_VIEW3_D_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_VIEW3_D, ChessView3DClass))
45
typedef struct _ChessView3D ChessView3D;
46
typedef struct _ChessView3DClass ChessView3DClass;
47
typedef struct _ChessView3DPrivate ChessView3DPrivate;
49
#define TYPE_TDS_MODEL (tds_model_get_type ())
50
#define TDS_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TDS_MODEL, TDSModel))
51
#define TDS_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TDS_MODEL, TDSModelClass))
52
#define IS_TDS_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TDS_MODEL))
53
#define IS_TDS_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TDS_MODEL))
54
#define TDS_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TDS_MODEL, TDSModelClass))
56
typedef struct _TDSModel TDSModel;
57
typedef struct _TDSModelClass TDSModelClass;
58
#define _tds_model_unref0(var) ((var == NULL) ? NULL : (var = (tds_model_unref (var), NULL)))
59
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
60
#define _g_free0(var) (var = (g_free (var), NULL))
61
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
62
#define _XFree0(var) ((var == NULL) ? NULL : (var = (XFree (var), NULL)))
64
#define TYPE_CHESS_SCENE (chess_scene_get_type ())
65
#define CHESS_SCENE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_SCENE, ChessScene))
66
#define CHESS_SCENE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_SCENE, ChessSceneClass))
67
#define IS_CHESS_SCENE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_SCENE))
68
#define IS_CHESS_SCENE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_SCENE))
69
#define CHESS_SCENE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_SCENE, ChessSceneClass))
71
typedef struct _ChessScene ChessScene;
72
typedef struct _ChessSceneClass ChessSceneClass;
74
#define TYPE_CHESS_GAME (chess_game_get_type ())
75
#define CHESS_GAME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_GAME, ChessGame))
76
#define CHESS_GAME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_GAME, ChessGameClass))
77
#define IS_CHESS_GAME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_GAME))
78
#define IS_CHESS_GAME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_GAME))
79
#define CHESS_GAME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_GAME, ChessGameClass))
81
typedef struct _ChessGame ChessGame;
82
typedef struct _ChessGameClass ChessGameClass;
83
typedef struct _ChessScenePrivate ChessScenePrivate;
85
#define TYPE_CHESS_MODEL (chess_model_get_type ())
86
#define CHESS_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_MODEL, ChessModel))
87
#define CHESS_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_MODEL, ChessModelClass))
88
#define IS_CHESS_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_MODEL))
89
#define IS_CHESS_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_MODEL))
90
#define CHESS_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_MODEL, ChessModelClass))
92
typedef struct _ChessModel ChessModel;
93
typedef struct _ChessModelClass ChessModelClass;
94
typedef struct _ChessModelPrivate ChessModelPrivate;
96
#define TYPE_CHESS_PIECE (chess_piece_get_type ())
97
#define CHESS_PIECE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_PIECE, ChessPiece))
98
#define CHESS_PIECE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_PIECE, ChessPieceClass))
99
#define IS_CHESS_PIECE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_PIECE))
100
#define IS_CHESS_PIECE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_PIECE))
101
#define CHESS_PIECE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_PIECE, ChessPieceClass))
103
typedef struct _ChessPiece ChessPiece;
104
typedef struct _ChessPieceClass ChessPieceClass;
105
#define _chess_model_unref0(var) ((var == NULL) ? NULL : (var = (chess_model_unref (var), NULL)))
106
#define _chess_piece_unref0(var) ((var == NULL) ? NULL : (var = (chess_piece_unref (var), NULL)))
107
typedef struct _ChessPiecePrivate ChessPiecePrivate;
109
#define TYPE_CHESS_PLAYER (chess_player_get_type ())
110
#define CHESS_PLAYER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CHESS_PLAYER, ChessPlayer))
111
#define CHESS_PLAYER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CHESS_PLAYER, ChessPlayerClass))
112
#define IS_CHESS_PLAYER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CHESS_PLAYER))
113
#define IS_CHESS_PLAYER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CHESS_PLAYER))
114
#define CHESS_PLAYER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CHESS_PLAYER, ChessPlayerClass))
116
typedef struct _ChessPlayer ChessPlayer;
117
typedef struct _ChessPlayerClass ChessPlayerClass;
119
#define TYPE_PIECE_TYPE (piece_type_get_type ())
120
typedef struct _ChessPlayerPrivate ChessPlayerPrivate;
122
#define TYPE_COLOR (color_get_type ())
123
#define _cairo_destroy0(var) ((var == NULL) ? NULL : (var = (cairo_destroy (var), NULL)))
124
#define _cairo_surface_destroy0(var) ((var == NULL) ? NULL : (var = (cairo_surface_destroy (var), NULL)))
127
GtkDrawingArea parent_instance;
128
ChessViewPrivate * priv;
131
struct _ChessViewClass {
132
GtkDrawingAreaClass parent_class;
135
struct _ChessView3D {
136
ChessView parent_instance;
137
ChessView3DPrivate * priv;
140
struct _ChessView3DClass {
141
ChessViewClass parent_class;
144
struct _ChessView3DPrivate {
147
GLXDrawable drawable;
150
TDSModel* pawn_model;
151
TDSModel* knight_model;
152
TDSModel* bishop_model;
153
TDSModel* rook_model;
154
TDSModel* queen_model;
155
TDSModel* king_model;
156
GLfloat* board_vertices;
157
gint board_vertices_length1;
158
gint _board_vertices_size_;
159
GLfloat* board_normals;
160
gint board_normals_length1;
161
gint _board_normals_size_;
162
GLushort* board_quads;
163
gint board_quads_length1;
164
gint _board_quads_size_;
165
GLfloat SQUARE_WIDTH;
167
GLfloat BOARD_BORDER;
168
GLfloat BOARD_CHAMFER;
169
GLfloat BOARD_INNER_WIDTH;
170
GLfloat BOARD_OUTER_WIDTH;
172
GLfloat white_piece_color[4];
173
GLfloat white_piece_specular[4];
174
GLfloat black_piece_color[4];
175
GLfloat black_piece_specular[4];
176
GLuint _board_texture;
177
GLuint _numbering_texture;
178
GLuint _piece_texture;
182
GObject parent_instance;
183
ChessScenePrivate * priv;
190
struct _ChessSceneClass {
191
GObjectClass parent_class;
195
GTypeInstance parent_instance;
196
volatile int ref_count;
197
ChessModelPrivate * priv;
203
gboolean under_threat;
204
gboolean is_selected;
207
struct _ChessModelClass {
208
GTypeClass parent_class;
209
void (*finalize) (ChessModel *self);
222
GTypeInstance parent_instance;
223
volatile int ref_count;
224
ChessPiecePrivate * priv;
229
struct _ChessPieceClass {
230
GTypeClass parent_class;
231
void (*finalize) (ChessPiece *self);
239
struct _ChessPlayer {
240
GObject parent_instance;
241
ChessPlayerPrivate * priv;
245
struct _ChessPlayerClass {
246
GObjectClass parent_class;
250
static gpointer chess_view3_d_parent_class = NULL;
252
GType chess_view_get_type (void) G_GNUC_CONST;
253
GType chess_view3_d_get_type (void) G_GNUC_CONST;
254
gpointer tds_model_ref (gpointer instance);
255
void tds_model_unref (gpointer instance);
256
GParamSpec* param_spec_tds_model (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
257
void value_set_tds_model (GValue* value, gpointer v_object);
258
void value_take_tds_model (GValue* value, gpointer v_object);
259
gpointer value_get_tds_model (const GValue* value);
260
GType tds_model_get_type (void) G_GNUC_CONST;
261
#define CHESS_VIEW3_D_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_CHESS_VIEW3_D, ChessView3DPrivate))
263
CHESS_VIEW3_D_DUMMY_PROPERTY
265
ChessView3D* chess_view3_d_new (void);
266
ChessView3D* chess_view3_d_construct (GType object_type);
267
ChessView* chess_view_new (void);
268
ChessView* chess_view_construct (GType object_type);
269
static void chess_view3_d_realize_cb (ChessView3D* self);
270
static void _chess_view3_d_realize_cb_gtk_widget_realize (GtkWidget* _sender, gpointer self);
271
static void chess_view3_d_unrealize_cb (ChessView3D* self);
272
static void _chess_view3_d_unrealize_cb_gtk_widget_unrealize (GtkWidget* _sender, gpointer self);
273
TDSModel* tds_model_new (GFile* file, GError** error);
274
TDSModel* tds_model_construct (GType object_type, GFile* file, GError** error);
275
static void chess_view3_d_create_board (ChessView3D* self);
276
static gboolean chess_view3_d_start_gl (ChessView3D* self);
277
static gboolean _context_equal (const GLXContext* s1, const GLXContext* s2);
278
static gboolean chess_view3_d_real_configure_event (GtkWidget* base, GdkEventConfigure* event);
279
static void chess_view3_d_accFrustum (ChessView3D* self, GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far, GLfloat pixdx, GLfloat pixdy, GLfloat eyedx, GLfloat eyedy, GLfloat focus);
280
static void chess_view3_d_accPerspective (ChessView3D* self, GLfloat fovy, GLfloat aspect, GLfloat near, GLfloat far, GLfloat pixdx, GLfloat pixdy, GLfloat eyedx, GLfloat eyedy, GLfloat focus);
281
static gboolean chess_view3_d_real_draw (GtkWidget* base, cairo_t* c);
282
GType chess_scene_get_type (void) G_GNUC_CONST;
283
ChessScene* chess_view_get_scene (ChessView* self);
284
gboolean chess_scene_get_show_3d_smooth (ChessScene* self);
285
static void chess_view3_d_transform_camera (ChessView3D* self);
286
gdouble chess_scene_get_board_angle (ChessScene* self);
287
static void chess_view3_d_draw_board (ChessView3D* self);
288
static void chess_view3_d_draw_numbering (ChessView3D* self);
289
static void chess_view3_d_draw_pieces (ChessView3D* self);
290
static GLuint chess_view3_d_get_board_texture (ChessView3D* self);
291
static GLuint chess_view3_d_get_numbering_texture (ChessView3D* self);
292
static void chess_view3_d_draw_label (ChessView3D* self, GLfloat x, GLfloat z, GLfloat width, gint cell);
293
gpointer chess_game_ref (gpointer instance);
294
void chess_game_unref (gpointer instance);
295
GParamSpec* param_spec_chess_game (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
296
void value_set_chess_game (GValue* value, gpointer v_object);
297
void value_take_chess_game (GValue* value, gpointer v_object);
298
gpointer value_get_chess_game (const GValue* value);
299
GType chess_game_get_type (void) G_GNUC_CONST;
300
ChessGame* chess_scene_get_game (ChessScene* self);
301
static GLuint chess_view3_d_get_piece_texture (ChessView3D* self);
302
gpointer chess_model_ref (gpointer instance);
303
void chess_model_unref (gpointer instance);
304
GParamSpec* param_spec_chess_model (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
305
void value_set_chess_model (GValue* value, gpointer v_object);
306
void value_take_chess_model (GValue* value, gpointer v_object);
307
gpointer value_get_chess_model (const GValue* value);
308
GType chess_model_get_type (void) G_GNUC_CONST;
309
gpointer chess_piece_ref (gpointer instance);
310
void chess_piece_unref (gpointer instance);
311
GParamSpec* param_spec_chess_piece (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
312
void value_set_chess_piece (GValue* value, gpointer v_object);
313
void value_take_chess_piece (GValue* value, gpointer v_object);
314
gpointer value_get_chess_piece (const GValue* value);
315
GType chess_piece_get_type (void) G_GNUC_CONST;
316
static void chess_view3_d_render_piece (ChessView3D* self, ChessPiece* piece, GLfloat alpha);
317
gboolean chess_scene_get_show_move_hints (ChessScene* self);
318
gboolean chess_scene_can_move (ChessScene* self, gint rank, gint file);
319
ChessPiece* chess_scene_get_selected_piece (ChessScene* self);
320
GType chess_player_get_type (void) G_GNUC_CONST;
321
GType piece_type_get_type (void) G_GNUC_CONST;
322
GType color_get_type (void) G_GNUC_CONST;
323
void tds_model_render (TDSModel* self);
324
static gboolean chess_view3_d_real_button_press_event (GtkWidget* base, GdkEventButton* event);
325
void chess_scene_select_square (ChessScene* self, gint file, gint rank);
326
static GLuint chess_view3_d_load_texture (ChessView3D* self, const gchar* filename);
327
static GLuint chess_view3_d_make_numbering_texture (ChessView3D* self);
328
static void chess_view3_d_draw_centered_text (ChessView3D* self, cairo_t* c, gdouble x, gdouble y, gdouble scale, const gchar* text);
329
static void chess_view3_d_finalize (GObject* obj);
330
static void _vala_chess_view3_d_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
333
static void _chess_view3_d_realize_cb_gtk_widget_realize (GtkWidget* _sender, gpointer self) {
334
chess_view3_d_realize_cb (self);
338
static void _chess_view3_d_unrealize_cb_gtk_widget_unrealize (GtkWidget* _sender, gpointer self) {
339
chess_view3_d_unrealize_cb (self);
343
ChessView3D* chess_view3_d_construct (GType object_type) {
344
ChessView3D * self = NULL;
345
GLfloat _tmp0_[4] = {0};
346
GLfloat _tmp1_[4] = {0};
347
GLfloat _tmp2_[4] = {0};
348
GLfloat _tmp3_[4] = {0};
349
gchar* _tmp4_ = NULL;
351
GFile* _tmp6_ = NULL;
353
TDSModel* _tmp8_ = NULL;
356
gchar* _tmp11_ = NULL;
358
GFile* _tmp13_ = NULL;
360
TDSModel* _tmp15_ = NULL;
363
gchar* _tmp18_ = NULL;
365
GFile* _tmp20_ = NULL;
367
TDSModel* _tmp22_ = NULL;
370
gchar* _tmp25_ = NULL;
372
GFile* _tmp27_ = NULL;
374
TDSModel* _tmp29_ = NULL;
377
gchar* _tmp32_ = NULL;
379
GFile* _tmp34_ = NULL;
381
TDSModel* _tmp36_ = NULL;
384
gchar* _tmp39_ = NULL;
386
GFile* _tmp41_ = NULL;
388
TDSModel* _tmp43_ = NULL;
391
GError * _inner_error_ = NULL;
392
self = (ChessView3D*) chess_view_construct (object_type);
393
self->priv->SQUARE_WIDTH = (GLfloat) 10.0f;
394
self->priv->BOARD_DEPTH = (GLfloat) 3.0f;
395
self->priv->BOARD_BORDER = (GLfloat) 5.0f;
396
self->priv->BOARD_CHAMFER = (GLfloat) 2.0f;
397
self->priv->BOARD_INNER_WIDTH = self->priv->SQUARE_WIDTH * 8.0f;
398
self->priv->BOARD_OUTER_WIDTH = self->priv->BOARD_INNER_WIDTH + (self->priv->BOARD_BORDER * 2.0f);
399
self->priv->OFFSET = self->priv->BOARD_OUTER_WIDTH * 0.5f;
400
gtk_widget_add_events ((GtkWidget*) self, (gint) GDK_BUTTON_PRESS_MASK);
401
g_signal_connect_object ((GtkWidget*) self, "realize", (GCallback) _chess_view3_d_realize_cb_gtk_widget_realize, self, 0);
402
g_signal_connect_object ((GtkWidget*) self, "unrealize", (GCallback) _chess_view3_d_unrealize_cb_gtk_widget_unrealize, self, 0);
403
_tmp0_[0] = (GLfloat) (0.95f * 0.7f);
404
_tmp0_[1] = (GLfloat) (0.81f * 0.7f);
405
_tmp0_[2] = (GLfloat) (0.64f * 0.7f);
406
_tmp0_[3] = (GLfloat) 1.0f;
407
memcpy (self->priv->white_piece_color, _tmp0_, 4 * sizeof (GLfloat));
408
_tmp1_[0] = (GLfloat) 0.95f;
409
_tmp1_[1] = (GLfloat) 0.81f;
410
_tmp1_[2] = (GLfloat) 0.64f;
411
_tmp1_[3] = (GLfloat) 1.0f;
412
memcpy (self->priv->white_piece_specular, _tmp1_, 4 * sizeof (GLfloat));
413
_tmp2_[0] = (GLfloat) (0.62f * 0.7f);
414
_tmp2_[1] = (GLfloat) (0.45f * 0.7f);
415
_tmp2_[2] = (GLfloat) (0.28f * 0.7f);
416
_tmp2_[3] = (GLfloat) 1.0f;
417
memcpy (self->priv->black_piece_color, _tmp2_, 4 * sizeof (GLfloat));
418
_tmp3_[0] = (GLfloat) 0.62f;
419
_tmp3_[1] = (GLfloat) 0.45f;
420
_tmp3_[2] = (GLfloat) 0.28f;
421
_tmp3_[3] = (GLfloat) 1.0f;
422
memcpy (self->priv->black_piece_specular, _tmp3_, 4 * sizeof (GLfloat));
423
gtk_widget_set_double_buffered ((GtkWidget*) self, FALSE);
424
_tmp4_ = g_build_filename (PKGDATADIR, "pieces", "3d", "pawn.3ds", NULL, NULL);
426
_tmp6_ = g_file_new_for_path (_tmp5_);
428
_tmp8_ = tds_model_new (_tmp7_, &_inner_error_);
430
_g_object_unref0 (_tmp7_);
433
if (_inner_error_ != NULL) {
434
goto __catch13_g_error;
436
_tds_model_unref0 (self->priv->pawn_model);
437
self->priv->pawn_model = _tmp10_;
438
_tmp11_ = g_build_filename (PKGDATADIR, "pieces", "3d", "knight.3ds", NULL, NULL);
440
_tmp13_ = g_file_new_for_path (_tmp12_);
442
_tmp15_ = tds_model_new (_tmp14_, &_inner_error_);
444
_g_object_unref0 (_tmp14_);
447
if (_inner_error_ != NULL) {
448
goto __catch13_g_error;
450
_tds_model_unref0 (self->priv->knight_model);
451
self->priv->knight_model = _tmp17_;
452
_tmp18_ = g_build_filename (PKGDATADIR, "pieces", "3d", "bishop.3ds", NULL, NULL);
454
_tmp20_ = g_file_new_for_path (_tmp19_);
456
_tmp22_ = tds_model_new (_tmp21_, &_inner_error_);
458
_g_object_unref0 (_tmp21_);
461
if (_inner_error_ != NULL) {
462
goto __catch13_g_error;
464
_tds_model_unref0 (self->priv->bishop_model);
465
self->priv->bishop_model = _tmp24_;
466
_tmp25_ = g_build_filename (PKGDATADIR, "pieces", "3d", "rook.3ds", NULL, NULL);
468
_tmp27_ = g_file_new_for_path (_tmp26_);
470
_tmp29_ = tds_model_new (_tmp28_, &_inner_error_);
472
_g_object_unref0 (_tmp28_);
475
if (_inner_error_ != NULL) {
476
goto __catch13_g_error;
478
_tds_model_unref0 (self->priv->rook_model);
479
self->priv->rook_model = _tmp31_;
480
_tmp32_ = g_build_filename (PKGDATADIR, "pieces", "3d", "queen.3ds", NULL, NULL);
482
_tmp34_ = g_file_new_for_path (_tmp33_);
484
_tmp36_ = tds_model_new (_tmp35_, &_inner_error_);
486
_g_object_unref0 (_tmp35_);
489
if (_inner_error_ != NULL) {
490
goto __catch13_g_error;
492
_tds_model_unref0 (self->priv->queen_model);
493
self->priv->queen_model = _tmp38_;
494
_tmp39_ = g_build_filename (PKGDATADIR, "pieces", "3d", "king.3ds", NULL, NULL);
496
_tmp41_ = g_file_new_for_path (_tmp40_);
498
_tmp43_ = tds_model_new (_tmp42_, &_inner_error_);
500
_g_object_unref0 (_tmp42_);
503
if (_inner_error_ != NULL) {
504
goto __catch13_g_error;
506
_tds_model_unref0 (self->priv->king_model);
507
self->priv->king_model = _tmp45_;
513
_inner_error_ = NULL;
517
if (_inner_error_ != NULL) {
518
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
519
g_clear_error (&_inner_error_);
522
chess_view3_d_create_board (self);
527
ChessView3D* chess_view3_d_new (void) {
528
return chess_view3_d_construct (TYPE_CHESS_VIEW3_D);
532
static gboolean _context_equal (const GLXContext* s1, const GLXContext* s2) {
542
return (*s1) == (*s2);
546
static gboolean chess_view3_d_start_gl (ChessView3D* self) {
547
gboolean result = FALSE;
548
GLXContext null_context;
550
g_return_val_if_fail (self != NULL, FALSE);
551
null_context = (GLXContext) NULL;
552
if (_context_equal (&self->priv->context, &null_context) == TRUE) {
556
_tmp0_ = glXMakeCurrent (self->priv->display, self->priv->drawable, self->priv->context);
562
static void chess_view3_d_create_board (ChessView3D* self) {
575
GLfloat* _tmp0_ = NULL;
576
GLfloat* _tmp1_ = NULL;
577
GLushort* _tmp2_ = NULL;
578
g_return_if_fail (self != NULL);
580
b = self->priv->BOARD_CHAMFER;
581
c = self->priv->BOARD_BORDER;
582
d = c + (self->priv->SQUARE_WIDTH * 8.0f);
583
e = (d + self->priv->BOARD_BORDER) - self->priv->BOARD_CHAMFER;
584
f = d + self->priv->BOARD_BORDER;
586
k = -self->priv->BOARD_CHAMFER;
587
j = -self->priv->BOARD_BORDER;
588
i = j - (self->priv->SQUARE_WIDTH * 8.0f);
589
h = (i - self->priv->BOARD_BORDER) + self->priv->BOARD_CHAMFER;
590
g = i - self->priv->BOARD_BORDER;
591
_tmp0_ = g_new0 (GLfloat, 48);
593
_tmp0_[1] = (GLfloat) 0.0f;
596
_tmp0_[4] = (GLfloat) 0.0f;
599
_tmp0_[7] = (GLfloat) 0.0f;
602
_tmp0_[10] = (GLfloat) 0.0f;
605
_tmp0_[13] = (GLfloat) 0.0f;
608
_tmp0_[16] = (GLfloat) 0.0f;
611
_tmp0_[19] = (GLfloat) 0.0f;
614
_tmp0_[22] = (GLfloat) 0.0f;
616
_tmp0_[24] = (GLfloat) a;
617
_tmp0_[25] = -self->priv->BOARD_CHAMFER;
620
_tmp0_[28] = -self->priv->BOARD_CHAMFER;
623
_tmp0_[31] = -self->priv->BOARD_CHAMFER;
624
_tmp0_[32] = (GLfloat) l;
625
_tmp0_[33] = (GLfloat) a;
626
_tmp0_[34] = -self->priv->BOARD_CHAMFER;
627
_tmp0_[35] = (GLfloat) l;
628
_tmp0_[36] = (GLfloat) a;
629
_tmp0_[37] = -self->priv->BOARD_DEPTH;
632
_tmp0_[40] = -self->priv->BOARD_DEPTH;
635
_tmp0_[43] = -self->priv->BOARD_DEPTH;
636
_tmp0_[44] = (GLfloat) l;
637
_tmp0_[45] = (GLfloat) a;
638
_tmp0_[46] = -self->priv->BOARD_DEPTH;
639
_tmp0_[47] = (GLfloat) l;
640
self->priv->board_vertices = (g_free (self->priv->board_vertices), NULL);
641
self->priv->board_vertices = _tmp0_;
642
self->priv->board_vertices_length1 = 48;
643
self->priv->_board_vertices_size_ = 48;
644
_tmp1_ = g_new0 (GLfloat, 27);
645
_tmp1_[0] = (GLfloat) 0.0f;
646
_tmp1_[1] = (GLfloat) 1.0f;
647
_tmp1_[2] = (GLfloat) 0.0f;
648
_tmp1_[3] = (GLfloat) 0.0f;
649
_tmp1_[4] = (GLfloat) 0.0f;
650
_tmp1_[5] = (GLfloat) (-1.0f);
651
_tmp1_[6] = (GLfloat) 1.0f;
652
_tmp1_[7] = (GLfloat) 0.0f;
653
_tmp1_[8] = (GLfloat) 0.0f;
654
_tmp1_[9] = (GLfloat) 0.0f;
655
_tmp1_[10] = (GLfloat) 0.0f;
656
_tmp1_[11] = (GLfloat) 1.0f;
657
_tmp1_[12] = (GLfloat) (-1.0f);
658
_tmp1_[13] = (GLfloat) 0.0f;
659
_tmp1_[14] = (GLfloat) 0.0f;
660
_tmp1_[15] = (GLfloat) 0.0f;
661
_tmp1_[16] = (GLfloat) 0.707f;
662
_tmp1_[17] = (GLfloat) (-0.707f);
663
_tmp1_[18] = (GLfloat) 0.707f;
664
_tmp1_[19] = (GLfloat) 0.707f;
665
_tmp1_[20] = (GLfloat) 0.0f;
666
_tmp1_[21] = (GLfloat) 0.0f;
667
_tmp1_[22] = (GLfloat) 0.707f;
668
_tmp1_[23] = (GLfloat) 0.707f;
669
_tmp1_[24] = (GLfloat) (-0.707f);
670
_tmp1_[25] = (GLfloat) 0.707f;
671
_tmp1_[26] = (GLfloat) 0.0f;
672
self->priv->board_normals = (g_free (self->priv->board_normals), NULL);
673
self->priv->board_normals = _tmp1_;
674
self->priv->board_normals_length1 = 27;
675
self->priv->_board_normals_size_ = 27;
676
_tmp2_ = g_new0 (GLushort, 60);
677
_tmp2_[0] = (GLushort) 0;
678
_tmp2_[1] = (GLushort) 1;
679
_tmp2_[2] = (GLushort) 5;
680
_tmp2_[3] = (GLushort) 4;
681
_tmp2_[4] = (GLushort) 0;
682
_tmp2_[5] = (GLushort) 1;
683
_tmp2_[6] = (GLushort) 2;
684
_tmp2_[7] = (GLushort) 6;
685
_tmp2_[8] = (GLushort) 5;
686
_tmp2_[9] = (GLushort) 0;
687
_tmp2_[10] = (GLushort) 2;
688
_tmp2_[11] = (GLushort) 3;
689
_tmp2_[12] = (GLushort) 7;
690
_tmp2_[13] = (GLushort) 6;
691
_tmp2_[14] = (GLushort) 0;
692
_tmp2_[15] = (GLushort) 3;
693
_tmp2_[16] = (GLushort) 0;
694
_tmp2_[17] = (GLushort) 4;
695
_tmp2_[18] = (GLushort) 7;
696
_tmp2_[19] = (GLushort) 0;
697
_tmp2_[20] = (GLushort) 4;
698
_tmp2_[21] = (GLushort) 5;
699
_tmp2_[22] = (GLushort) 9;
700
_tmp2_[23] = (GLushort) 8;
701
_tmp2_[24] = (GLushort) 5;
702
_tmp2_[25] = (GLushort) 5;
703
_tmp2_[26] = (GLushort) 6;
704
_tmp2_[27] = (GLushort) 10;
705
_tmp2_[28] = (GLushort) 9;
706
_tmp2_[29] = (GLushort) 6;
707
_tmp2_[30] = (GLushort) 6;
708
_tmp2_[31] = (GLushort) 7;
709
_tmp2_[32] = (GLushort) 11;
710
_tmp2_[33] = (GLushort) 10;
711
_tmp2_[34] = (GLushort) 7;
712
_tmp2_[35] = (GLushort) 7;
713
_tmp2_[36] = (GLushort) 4;
714
_tmp2_[37] = (GLushort) 8;
715
_tmp2_[38] = (GLushort) 11;
716
_tmp2_[39] = (GLushort) 8;
717
_tmp2_[40] = (GLushort) 8;
718
_tmp2_[41] = (GLushort) 9;
719
_tmp2_[42] = (GLushort) 13;
720
_tmp2_[43] = (GLushort) 12;
721
_tmp2_[44] = (GLushort) 1;
722
_tmp2_[45] = (GLushort) 9;
723
_tmp2_[46] = (GLushort) 10;
724
_tmp2_[47] = (GLushort) 14;
725
_tmp2_[48] = (GLushort) 13;
726
_tmp2_[49] = (GLushort) 2;
727
_tmp2_[50] = (GLushort) 10;
728
_tmp2_[51] = (GLushort) 11;
729
_tmp2_[52] = (GLushort) 15;
730
_tmp2_[53] = (GLushort) 14;
731
_tmp2_[54] = (GLushort) 3;
732
_tmp2_[55] = (GLushort) 11;
733
_tmp2_[56] = (GLushort) 8;
734
_tmp2_[57] = (GLushort) 12;
735
_tmp2_[58] = (GLushort) 15;
736
_tmp2_[59] = (GLushort) 4;
737
self->priv->board_quads = (g_free (self->priv->board_quads), NULL);
738
self->priv->board_quads = _tmp2_;
739
self->priv->board_quads_length1 = 60;
740
self->priv->_board_quads_size_ = 60;
744
static void chess_view3_d_realize_cb (ChessView3D* self) {
747
gint attributes_length1;
748
gint _attributes_size_;
749
GdkWindow* _tmp1_ = NULL;
751
GdkWindow* _tmp3_ = NULL;
752
GdkDisplay* _tmp4_ = NULL;
753
Display* _tmp5_ = NULL;
754
GdkScreen* _tmp6_ = NULL;
757
XVisualInfo* _tmp8_ = NULL;
759
g_return_if_fail (self != NULL);
760
_tmp0_ = g_new0 (gint, 17);
761
_tmp0_[0] = GLX_RGBA;
762
_tmp0_[1] = GLX_RED_SIZE;
764
_tmp0_[3] = GLX_GREEN_SIZE;
766
_tmp0_[5] = GLX_BLUE_SIZE;
768
_tmp0_[7] = GLX_DOUBLEBUFFER;
769
_tmp0_[8] = GLX_DEPTH_SIZE;
771
_tmp0_[10] = GLX_ACCUM_RED_SIZE;
773
_tmp0_[12] = GLX_ACCUM_GREEN_SIZE;
775
_tmp0_[14] = GLX_ACCUM_BLUE_SIZE;
779
attributes_length1 = 17;
780
_attributes_size_ = 17;
781
_tmp1_ = gtk_widget_get_window ((GtkWidget*) self);
782
_tmp2_ = gdk_x11_window_get_xid (_tmp1_);
783
self->priv->drawable = (GLXDrawable) _tmp2_;
784
_tmp3_ = gtk_widget_get_window ((GtkWidget*) self);
785
_tmp4_ = gdk_window_get_display (_tmp3_);
786
_tmp5_ = gdk_x11_display_get_xdisplay (_tmp4_);
787
self->priv->display = _tmp5_;
788
_tmp6_ = gtk_widget_get_screen ((GtkWidget*) self);
789
_tmp7_ = gdk_x11_screen_get_screen_number (_tmp6_);
791
_tmp8_ = glXChooseVisual (self->priv->display, screen, attributes);
793
if (visual == NULL) {
794
g_warning ("chess-view-3d.vala:167: Failed to get GLX visual on display %p, screen" \
795
" %d", self->priv->display, screen);
798
GLXContext null_context;
799
_tmp9_ = glXCreateContext (self->priv->display, visual, NULL, TRUE);
800
self->priv->context = _tmp9_;
801
null_context = (GLXContext) NULL;
802
if (_context_equal (&self->priv->context, &null_context) == TRUE) {
803
g_warning ("chess-view-3d.vala:173: Failed to create GLX context");
807
attributes = (g_free (attributes), NULL);
811
static void chess_view3_d_unrealize_cb (ChessView3D* self) {
812
GLXContext null_context;
814
g_return_if_fail (self != NULL);
815
null_context = (GLXContext) NULL;
816
if (_context_equal (&self->priv->context, &null_context) == TRUE) {
819
_tmp0_ = glXGetCurrentDrawable ();
820
if (self->priv->drawable == _tmp0_) {
822
glXMakeCurrent (self->priv->display, (GLXDrawable) None, (GLXContext) NULL);
824
glXDestroyContext (self->priv->display, self->priv->context);
828
static gboolean chess_view3_d_real_configure_event (GtkWidget* base, GdkEventConfigure* event) {
830
gboolean result = FALSE;
837
self = (ChessView3D*) base;
838
_tmp0_ = gtk_widget_get_allocated_width ((GtkWidget*) self);
839
_tmp1_ = gtk_widget_get_allocated_height ((GtkWidget*) self);
840
_tmp2_ = MIN (_tmp0_, _tmp1_);
842
_tmp3_ = floor ((short_edge - (2 * self->priv->border)) / 9.0);
843
self->priv->square_size = (gint) _tmp3_;
844
_tmp4_ = chess_view3_d_start_gl (self);
848
_tmp5_ = gtk_widget_get_allocated_width ((GtkWidget*) self);
849
_tmp6_ = gtk_widget_get_allocated_height ((GtkWidget*) self);
850
glViewport ((GLint) 0, (GLint) 0, (GLsizei) _tmp5_, (GLsizei) _tmp6_);
857
static void chess_view3_d_accFrustum (ChessView3D* self, GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far, GLfloat pixdx, GLfloat pixdy, GLfloat eyedx, GLfloat eyedy, GLfloat focus) {
864
g_return_if_fail (self != NULL);
865
xwsize = right - left;
866
ywsize = top - bottom;
867
_tmp0_ = gtk_widget_get_allocated_width ((GtkWidget*) self);
868
dx = -(((pixdx * xwsize) / _tmp0_) + ((eyedx * near) / focus));
869
_tmp1_ = gtk_widget_get_allocated_height ((GtkWidget*) self);
870
dy = -(((pixdy * ywsize) / _tmp1_) + ((eyedy * near) / focus));
871
glFrustum ((GLdouble) (left + dx), (GLdouble) (right + dx), (GLdouble) (bottom + dy), (GLdouble) (top + dy), (GLdouble) near, (GLdouble) far);
872
glTranslatef (-eyedx, -eyedy, (GLfloat) 0.0f);
876
static void chess_view3_d_accPerspective (ChessView3D* self, GLfloat fovy, GLfloat aspect, GLfloat near, GLfloat far, GLfloat pixdx, GLfloat pixdy, GLfloat eyedx, GLfloat eyedy, GLfloat focus) {
884
g_return_if_fail (self != NULL);
885
fov2 = ((fovy * ((GLfloat) G_PI)) / 180.0f) / 2.0f;
886
_tmp0_ = cos ((gdouble) fov2);
887
_tmp1_ = sin ((gdouble) fov2);
888
top = near / (((GLfloat) _tmp0_) / ((GLfloat) _tmp1_));
890
right = top * aspect;
892
chess_view3_d_accFrustum (self, left, right, bottom, top, near, far, pixdx, pixdy, eyedx, eyedy, focus);
896
static gboolean chess_view3_d_real_draw (GtkWidget* base, cairo_t* c) {
898
gboolean result = FALSE;
899
GLfloat* _tmp0_ = NULL;
901
gint jitters_length1;
905
ChessScene* _tmp2_ = NULL;
907
ChessScene* _tmp18_ = NULL;
909
self = (ChessView3D*) base;
910
g_return_val_if_fail (c != NULL, FALSE);
911
_tmp0_ = g_new0 (GLfloat, 6);
912
_tmp0_[0] = (GLfloat) 0.0033922635f;
913
_tmp0_[1] = (GLfloat) 0.3317967229f;
914
_tmp0_[2] = (GLfloat) 0.2806016275f;
915
_tmp0_[3] = (GLfloat) (-0.2495619123f);
916
_tmp0_[4] = (GLfloat) (-0.273817106f);
917
_tmp0_[5] = (GLfloat) (-0.086844639f);
921
_tmp1_ = chess_view3_d_start_gl (self);
924
jitters = (g_free (jitters), NULL);
928
_tmp2_ = chess_view_get_scene ((ChessView*) self);
929
_tmp3_ = chess_scene_get_show_3d_smooth (_tmp2_);
931
glClear ((GLbitfield) GL_ACCUM_BUFFER_BIT);
941
GtkStyle* _tmp5_ = NULL;
944
ChessScene* _tmp7_ = NULL;
946
GLfloat* _tmp13_ = NULL;
950
ChessScene* _tmp14_ = NULL;
952
ChessScene* _tmp16_ = NULL;
958
if (!(i < n_passes)) {
961
_tmp5_ = gtk_widget_get_style ((GtkWidget*) self);
962
_tmp6_ = gtk_widget_get_state ((GtkWidget*) self);
963
bg = _tmp5_->bg[_tmp6_];
964
glClearColor ((GLclampf) (bg.red / 65535.0f), (GLclampf) (bg.green / 65535.0f), (GLclampf) (bg.blue / 65535.0f), (GLclampf) 1.0f);
965
glClear ((GLbitfield) (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
966
glEnable (GL_DEPTH_TEST);
967
glMatrixMode (GL_PROJECTION);
969
_tmp7_ = chess_view_get_scene ((ChessView*) self);
970
_tmp8_ = chess_scene_get_show_3d_smooth (_tmp7_);
974
_tmp9_ = gtk_widget_get_allocated_width ((GtkWidget*) self);
975
_tmp10_ = gtk_widget_get_allocated_height ((GtkWidget*) self);
976
chess_view3_d_accPerspective (self, (GLfloat) 60.0f, (GLfloat) (((gfloat) _tmp9_) / _tmp10_), (GLfloat) 0.1f, (GLfloat) 1000, jitters[i * 2], jitters[(i * 2) + 1], (GLfloat) 0, (GLfloat) 0, (GLfloat) 1);
980
_tmp11_ = gtk_widget_get_allocated_width ((GtkWidget*) self);
981
_tmp12_ = gtk_widget_get_allocated_height ((GtkWidget*) self);
982
gluPerspective ((GLdouble) 60.0f, (GLdouble) (((gfloat) _tmp11_) / _tmp12_), (GLdouble) 0.1f, (GLdouble) 1000);
984
glMatrixMode (GL_MODELVIEW);
985
chess_view3_d_transform_camera (self);
986
_tmp13_ = g_new0 (GLfloat, 4);
987
_tmp13_[0] = (GLfloat) 100.0f;
988
_tmp13_[1] = (GLfloat) 100.0f;
989
_tmp13_[2] = (GLfloat) 100.0f;
990
_tmp13_[3] = (GLfloat) 1.0f;
994
glLightfv (GL_LIGHT0, GL_POSITION, pos);
995
glEnable (GL_LIGHTING);
996
glEnable (GL_LIGHT0);
998
_tmp14_ = chess_view_get_scene ((ChessView*) self);
999
_tmp15_ = chess_scene_get_board_angle (_tmp14_);
1000
glRotatef ((GLfloat) _tmp15_, (GLfloat) 0.0f, (GLfloat) 1.0f, (GLfloat) 0.0f);
1001
glTranslatef (-self->priv->OFFSET, (GLfloat) 0.0f, self->priv->OFFSET);
1002
chess_view3_d_draw_board (self);
1003
chess_view3_d_draw_numbering (self);
1004
chess_view3_d_draw_pieces (self);
1006
_tmp16_ = chess_view_get_scene ((ChessView*) self);
1007
_tmp17_ = chess_scene_get_show_3d_smooth (_tmp16_);
1009
glAccum (GL_ACCUM, (GLfloat) (1.0f / n_passes));
1011
pos = (g_free (pos), NULL);
1015
_tmp18_ = chess_view_get_scene ((ChessView*) self);
1016
_tmp19_ = chess_scene_get_show_3d_smooth (_tmp18_);
1018
glAccum (GL_RETURN, (GLfloat) 1);
1020
glXSwapBuffers (self->priv->display, self->priv->drawable);
1022
jitters = (g_free (jitters), NULL);
1027
static void chess_view3_d_draw_board (ChessView3D* self) {
1029
g_return_if_fail (self != NULL);
1030
glEnable (GL_COLOR_MATERIAL);
1031
glColor3f ((GLfloat) (0x2e / 255.f), (GLfloat) (0x34 / 255.f), (GLfloat) (0x36 / 255.f));
1045
if (!(i < self->priv->board_quads_length1)) {
1048
j = self->priv->board_quads[i + 4] * 3;
1049
glNormal3f (self->priv->board_normals[j], self->priv->board_normals[j + 1], self->priv->board_normals[j + 2]);
1050
j = self->priv->board_quads[i] * 3;
1051
glVertex3f (self->priv->board_vertices[j], self->priv->board_vertices[j + 1], self->priv->board_vertices[j + 2]);
1052
j = self->priv->board_quads[i + 1] * 3;
1053
glVertex3f (self->priv->board_vertices[j], self->priv->board_vertices[j + 1], self->priv->board_vertices[j + 2]);
1054
j = self->priv->board_quads[i + 2] * 3;
1055
glVertex3f (self->priv->board_vertices[j], self->priv->board_vertices[j + 1], self->priv->board_vertices[j + 2]);
1056
j = self->priv->board_quads[i + 3] * 3;
1057
glVertex3f (self->priv->board_vertices[j], self->priv->board_vertices[j + 1], self->priv->board_vertices[j + 2]);
1062
glEnable (GL_TEXTURE_2D);
1063
_tmp1_ = chess_view3_d_get_board_texture (self);
1064
glBindTexture (GL_TEXTURE_2D, _tmp1_);
1065
glNormal3f ((GLfloat) 0.0f, (GLfloat) 1.0f, (GLfloat) 0.0f);
1098
if (((file + rank) % 2) == 0) {
1099
glColor3f ((GLfloat) (0xee / 255.f), (GLfloat) (0xee / 255.f), (GLfloat) (0xec / 255.f));
1101
glColor3f ((GLfloat) (0xba / 255.f), (GLfloat) (0xbd / 255.f), (GLfloat) (0xb6 / 255.f));
1104
x0 = self->priv->BOARD_BORDER + (file * self->priv->SQUARE_WIDTH);
1105
x1 = x0 + self->priv->SQUARE_WIDTH;
1106
z0 = self->priv->BOARD_BORDER + (rank * self->priv->SQUARE_WIDTH);
1107
z1 = z0 + self->priv->SQUARE_WIDTH;
1108
glTexCoord2f ((GLfloat) 0.0f, (GLfloat) 0.0f);
1109
glVertex3f (x0, (GLfloat) 0.0f, -z0);
1110
glTexCoord2f ((GLfloat) 1.0f, (GLfloat) 0.0f);
1111
glVertex3f (x1, (GLfloat) 0.0f, -z0);
1112
glTexCoord2f ((GLfloat) 1.0f, (GLfloat) 1.0f);
1113
glVertex3f (x1, (GLfloat) 0.0f, -z1);
1114
glTexCoord2f ((GLfloat) 0.0f, (GLfloat) 1.0f);
1115
glVertex3f (x0, (GLfloat) 0.0f, -z1);
1123
glDisable (GL_TEXTURE_2D);
1124
glDisable (GL_COLOR_MATERIAL);
1128
static void chess_view3_d_draw_numbering (ChessView3D* self) {
1130
GLfloat text_offset;
1132
GLfloat white_z_offset;
1133
GLfloat black_z_offset;
1134
GLfloat left_offset;
1135
GLfloat right_offset;
1137
g_return_if_fail (self != NULL);
1138
text_width = self->priv->BOARD_BORDER * 0.8f;
1139
text_offset = (self->priv->BOARD_BORDER + self->priv->BOARD_CHAMFER) * 0.5f;
1140
offset = self->priv->BOARD_BORDER + (self->priv->SQUARE_WIDTH * 0.5f);
1141
white_z_offset = -text_offset;
1142
black_z_offset = (-self->priv->BOARD_OUTER_WIDTH) + text_offset;
1143
left_offset = text_offset;
1144
right_offset = self->priv->BOARD_OUTER_WIDTH - text_offset;
1145
glDisable (GL_DEPTH_TEST);
1146
glEnable (GL_TEXTURE_2D);
1147
glEnable (GL_COLOR_MATERIAL);
1148
glEnable (GL_BLEND);
1149
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1150
_tmp0_ = chess_view3_d_get_numbering_texture (self);
1151
glBindTexture (GL_TEXTURE_2D, _tmp0_);
1152
glColor3f ((GLfloat) 1, (GLfloat) 1, (GLfloat) 1);
1153
glNormal3f ((GLfloat) 0.0f, (GLfloat) 1.0f, (GLfloat) 0.0f);
1168
chess_view3_d_draw_label (self, left_offset, -offset, text_width, i + 8);
1169
chess_view3_d_draw_label (self, right_offset, -offset, text_width, i + 8);
1170
chess_view3_d_draw_label (self, offset, white_z_offset, text_width, i);
1171
chess_view3_d_draw_label (self, offset, black_z_offset, text_width, i);
1172
offset = offset + self->priv->SQUARE_WIDTH;
1176
glDisable (GL_BLEND);
1177
glDisable (GL_COLOR_MATERIAL);
1178
glDisable (GL_TEXTURE_2D);
1182
static void chess_view3_d_draw_label (ChessView3D* self, GLfloat x, GLfloat z, GLfloat width, gint cell) {
1185
g_return_if_fail (self != NULL);
1186
w = (GLfloat) (1.0f / 16);
1187
l = (GLfloat) (cell / 16.0f);
1189
glTranslatef (x, (GLfloat) 0.0f, z);
1191
glTexCoord2f (l, (GLfloat) 0.0f);
1192
glVertex3f ((-width) / 2, (GLfloat) 0.0f, (-width) / 2);
1193
glTexCoord2f (l, (GLfloat) 1.0f);
1194
glVertex3f ((-width) / 2, (GLfloat) 0.0f, width / 2);
1195
glTexCoord2f (l + w, (GLfloat) 1.0f);
1196
glVertex3f (width / 2, (GLfloat) 0.0f, width / 2);
1197
glTexCoord2f (l + w, (GLfloat) 0.0f);
1198
glVertex3f (width / 2, (GLfloat) 0.0f, (-width) / 2);
1204
static gpointer _chess_model_ref0 (gpointer self) {
1205
return self ? chess_model_ref (self) : NULL;
1209
static void chess_view3_d_draw_pieces (ChessView3D* self) {
1210
ChessScene* _tmp0_ = NULL;
1211
ChessGame* _tmp1_ = NULL;
1213
ChessScene* _tmp3_ = NULL;
1214
g_return_if_fail (self != NULL);
1215
_tmp0_ = chess_view_get_scene ((ChessView*) self);
1216
_tmp1_ = chess_scene_get_game (_tmp0_);
1217
if (_tmp1_ == NULL) {
1220
glEnable (GL_DEPTH_TEST);
1221
glEnable (GL_TEXTURE_2D);
1222
_tmp2_ = chess_view3_d_get_piece_texture (self);
1223
glBindTexture (GL_TEXTURE_2D, _tmp2_);
1224
_tmp3_ = chess_view_get_scene ((ChessView*) self);
1226
GList* model_collection;
1228
model_collection = _tmp3_->pieces;
1229
for (model_it = model_collection; model_it != NULL; model_it = model_it->next) {
1232
_tmp4_ = _chess_model_ref0 ((ChessModel*) model_it->data);
1236
glTranslatef ((self->priv->BOARD_BORDER + (((GLfloat) model->x) * self->priv->SQUARE_WIDTH)) + (self->priv->SQUARE_WIDTH / 2), (GLfloat) 0.0f, -((self->priv->BOARD_BORDER + (((GLfloat) model->y) * self->priv->SQUARE_WIDTH)) + (self->priv->SQUARE_WIDTH / 2)));
1237
if (model->is_selected) {
1238
glTranslatef ((GLfloat) 0.0f, self->priv->SQUARE_WIDTH * 0.4f, (GLfloat) 0.0f);
1240
chess_view3_d_render_piece (self, model->piece, (GLfloat) 1.0f);
1242
_chess_model_unref0 (model);
1267
gboolean _tmp7_ = FALSE;
1268
ChessScene* _tmp8_ = NULL;
1277
_tmp8_ = chess_view_get_scene ((ChessView*) self);
1278
_tmp9_ = chess_scene_get_show_move_hints (_tmp8_);
1280
ChessScene* _tmp10_ = NULL;
1282
_tmp10_ = chess_view_get_scene ((ChessView*) self);
1283
_tmp11_ = chess_scene_can_move (_tmp10_, rank, file);
1289
ChessScene* _tmp12_ = NULL;
1290
ChessPiece* _tmp13_ = NULL;
1291
ChessPiece* _tmp14_;
1293
glTranslatef ((self->priv->BOARD_BORDER + (file * self->priv->SQUARE_WIDTH)) + (self->priv->SQUARE_WIDTH / 2), (GLfloat) 0.0f, -((self->priv->BOARD_BORDER + (rank * self->priv->SQUARE_WIDTH)) + (self->priv->SQUARE_WIDTH / 2)));
1294
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1295
glEnable (GL_BLEND);
1296
glDisable (GL_DEPTH_TEST);
1297
_tmp12_ = chess_view_get_scene ((ChessView*) self);
1298
_tmp13_ = chess_scene_get_selected_piece (_tmp12_);
1300
chess_view3_d_render_piece (self, _tmp14_, (GLfloat) 0.1f);
1301
_chess_piece_unref0 (_tmp14_);
1302
glEnable (GL_DEPTH_TEST);
1303
glDisable (GL_BLEND);
1312
glDisable (GL_TEXTURE_2D);
1316
static void chess_view3_d_render_piece (ChessView3D* self, ChessPiece* piece, GLfloat alpha) {
1317
static const GLfloat black[] = {(GLfloat) 0.0f, (GLfloat) 0.0f, (GLfloat) 0.0f, (GLfloat) 0.0f};
1318
g_return_if_fail (self != NULL);
1319
g_return_if_fail (piece != NULL);
1320
self->priv->white_piece_color[3] = alpha;
1321
self->priv->black_piece_color[3] = alpha;
1322
if (piece->player->color == COLOR_WHITE) {
1323
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, self->priv->white_piece_color);
1324
glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, self->priv->white_piece_specular);
1326
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, self->priv->black_piece_color);
1327
glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, self->priv->black_piece_specular);
1329
glMaterialfv (GL_FRONT_AND_BACK, GL_EMISSION, black);
1330
glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, (GLfloat) 64.0f);
1331
if (piece->player->color == COLOR_BLACK) {
1332
glRotatef ((GLfloat) 180.0f, (GLfloat) 0.0f, (GLfloat) 1.0f, (GLfloat) 0.0f);
1334
switch (piece->type) {
1335
case PIECE_TYPE_PAWN:
1337
tds_model_render (self->priv->pawn_model);
1340
case PIECE_TYPE_ROOK:
1342
tds_model_render (self->priv->rook_model);
1345
case PIECE_TYPE_KNIGHT:
1347
tds_model_render (self->priv->knight_model);
1350
case PIECE_TYPE_BISHOP:
1352
tds_model_render (self->priv->bishop_model);
1355
case PIECE_TYPE_QUEEN:
1357
tds_model_render (self->priv->queen_model);
1360
case PIECE_TYPE_KING:
1362
tds_model_render (self->priv->king_model);
1371
static gboolean chess_view3_d_real_button_press_event (GtkWidget* base, GdkEventButton* event) {
1373
gboolean result = FALSE;
1374
gboolean _tmp0_ = FALSE;
1375
ChessScene* _tmp1_ = NULL;
1376
ChessGame* _tmp2_ = NULL;
1378
GLuint buffer[20] = {0};
1381
GLint* _tmp6_ = NULL;
1383
gint viewport_length1;
1384
gint _viewport_size_;
1388
ChessScene* _tmp10_ = NULL;
1392
self = (ChessView3D*) base;
1393
_tmp1_ = chess_view_get_scene ((ChessView*) self);
1394
_tmp2_ = chess_scene_get_game (_tmp1_);
1395
if (_tmp2_ == NULL) {
1398
_tmp0_ = (*event).button != 1;
1404
_tmp3_ = chess_view3_d_start_gl (self);
1409
glSelectBuffer ((GLsizei) 20, buffer);
1410
glRenderMode (GL_SELECT);
1412
glMatrixMode (GL_PROJECTION);
1414
_tmp4_ = gtk_widget_get_allocated_width ((GtkWidget*) self);
1415
_tmp5_ = gtk_widget_get_allocated_height ((GtkWidget*) self);
1416
_tmp6_ = g_new0 (GLint, 4);
1417
_tmp6_[0] = (GLint) 0;
1418
_tmp6_[1] = (GLint) 0;
1419
_tmp6_[2] = (GLint) _tmp4_;
1420
_tmp6_[3] = (GLint) _tmp5_;
1422
viewport_length1 = 4;
1423
_viewport_size_ = 4;
1424
_tmp7_ = gtk_widget_get_allocated_height ((GtkWidget*) self);
1425
gluPickMatrix ((GLdouble) (*event).x, (GLdouble) (((gfloat) _tmp7_) - (*event).y), (GLdouble) 1.0, (GLdouble) 1.0, viewport);
1426
_tmp8_ = gtk_widget_get_allocated_width ((GtkWidget*) self);
1427
_tmp9_ = gtk_widget_get_allocated_height ((GtkWidget*) self);
1428
gluPerspective ((GLdouble) 60.0, (GLdouble) (((gfloat) _tmp8_) / ((gfloat) _tmp9_)), (GLdouble) 0, (GLdouble) 1);
1429
glMatrixMode (GL_MODELVIEW);
1431
chess_view3_d_transform_camera (self);
1432
_tmp10_ = chess_view_get_scene ((ChessView*) self);
1433
_tmp11_ = chess_scene_get_board_angle (_tmp10_);
1434
glRotatef ((GLfloat) _tmp11_, (GLfloat) 0.0f, (GLfloat) 1.0f, (GLfloat) 0.0f);
1435
glTranslatef (-self->priv->OFFSET, (GLfloat) 0.0f, self->priv->OFFSET);
1450
glPushName ((GLuint) rank);
1469
glPushName ((GLuint) file);
1471
x0 = self->priv->BOARD_BORDER + (file * self->priv->SQUARE_WIDTH);
1472
x1 = x0 + self->priv->SQUARE_WIDTH;
1473
z0 = self->priv->BOARD_BORDER + (rank * self->priv->SQUARE_WIDTH);
1474
z1 = z0 + self->priv->SQUARE_WIDTH;
1475
glVertex3f (x0, (GLfloat) 0.0f, -z0);
1476
glVertex3f (x1, (GLfloat) 0.0f, -z0);
1477
glVertex3f (x1, (GLfloat) 0.0f, -z1);
1478
glVertex3f (x0, (GLfloat) 0.0f, -z1);
1489
_tmp14_ = glRenderMode (GL_RENDER);
1494
ChessScene* _tmp15_ = NULL;
1497
_tmp15_ = chess_view_get_scene ((ChessView*) self);
1498
chess_scene_select_square (_tmp15_, (gint) file, (gint) rank);
1501
viewport = (g_free (viewport), NULL);
1506
static void chess_view3_d_transform_camera (ChessView3D* self) {
1507
g_return_if_fail (self != NULL);
1509
gluLookAt ((GLdouble) 0.0, (GLdouble) 80.0, (GLdouble) 40.0, (GLdouble) 0.0, (GLdouble) 0.0, (GLdouble) 5.0, (GLdouble) 0.0, (GLdouble) 1.0, (GLdouble) 0.0);
1513
static GLuint chess_view3_d_load_texture (ChessView3D* self, const gchar* filename) {
1515
GdkPixbuf* pixbuf = NULL;
1516
GdkPixbuf* _tmp0_ = NULL;
1520
GLuint textures[1] = {0};
1525
void* _tmp8_ = NULL;
1526
GError * _inner_error_ = NULL;
1527
g_return_val_if_fail (self != NULL, 0U);
1528
g_return_val_if_fail (filename != NULL, 0U);
1529
_tmp0_ = gdk_pixbuf_new_from_file (filename, &_inner_error_);
1531
if (_inner_error_ != NULL) {
1532
goto __catch14_g_error;
1534
_g_object_unref0 (pixbuf);
1541
_inner_error_ = NULL;
1542
g_warning ("chess-view-3d.vala:579: Error loading texture %s: %s", filename, e->message);
1543
result = (GLuint) 0;
1545
_g_object_unref0 (pixbuf);
1549
if (_inner_error_ != NULL) {
1550
_g_object_unref0 (pixbuf);
1551
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
1552
g_clear_error (&_inner_error_);
1555
_tmp2_ = gdk_pixbuf_get_n_channels (pixbuf);
1557
format = GL_LUMINANCE;
1560
_tmp3_ = gdk_pixbuf_get_n_channels (pixbuf);
1565
_tmp4_ = gdk_pixbuf_get_n_channels (pixbuf);
1569
g_warning ("chess-view-3d.vala:592: Unknown format image");
1570
result = (GLuint) 0;
1571
_g_object_unref0 (pixbuf);
1576
glGenTextures ((GLsizei) 1, textures);
1578
glBindTexture (GL_TEXTURE_2D, t);
1579
glPixelStorei (GL_UNPACK_ALIGNMENT, (GLint) 1);
1580
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (GLint) GL_REPEAT);
1581
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (GLint) GL_REPEAT);
1582
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (GLint) GL_LINEAR);
1583
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (GLint) GL_LINEAR);
1584
_tmp5_ = gdk_pixbuf_get_n_channels (pixbuf);
1585
_tmp6_ = gdk_pixbuf_get_width (pixbuf);
1586
_tmp7_ = gdk_pixbuf_get_height (pixbuf);
1587
_tmp8_ = gdk_pixbuf_get_pixels (pixbuf);
1588
gluBuild2DMipmaps (GL_TEXTURE_2D, (GLint) _tmp5_, (GLsizei) _tmp6_, (GLsizei) _tmp7_, format, GL_UNSIGNED_BYTE, _tmp8_);
1590
_g_object_unref0 (pixbuf);
1595
static GLuint chess_view3_d_make_numbering_texture (ChessView3D* self) {
1600
gint texture_height;
1601
cairo_surface_t* _tmp0_ = NULL;
1602
cairo_surface_t* surface;
1603
cairo_t* _tmp1_ = NULL;
1605
cairo_font_extents_t extents = {0};
1606
cairo_font_extents_t _tmp2_ = {0};
1610
GLuint textures[1] = {0};
1612
guchar* _tmp6_ = NULL;
1613
g_return_val_if_fail (self != NULL, 0U);
1616
texture_width = width * 16;
1617
texture_height = height;
1618
_tmp0_ = cairo_image_surface_create (CAIRO_FORMAT_A8, texture_width, texture_height);
1620
_tmp1_ = cairo_create (surface);
1622
cairo_set_source_rgba (c, 1.0, 1.0, 1.0, 1.0);
1623
cairo_select_font_face (c, "sans-serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
1624
cairo_set_font_size (c, (gdouble) width);
1625
cairo_font_extents (c, &_tmp2_);
1627
scale = width / (extents.ascent + extents.descent);
1628
yoffset = height * 0.5;
1629
xoffset = width * 0.5;
1637
gchar* _tmp4_ = NULL;
1639
gchar* _tmp5_ = NULL;
1648
_tmp4_ = g_strdup_printf ("%c", 'a' + i);
1650
_tmp5_ = g_strdup_printf ("%c", '1' + i);
1652
chess_view3_d_draw_centered_text (self, c, xoffset, yoffset, scale, f);
1653
chess_view3_d_draw_centered_text (self, c, xoffset + (width * 8), yoffset, scale, r);
1654
xoffset = xoffset + ((gdouble) width);
1660
glGenTextures ((GLsizei) 1, textures);
1662
glBindTexture (GL_TEXTURE_2D, t);
1663
glPixelStorei (GL_UNPACK_ALIGNMENT, (GLint) 1);
1664
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (GLint) GL_REPEAT);
1665
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (GLint) GL_REPEAT);
1666
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (GLint) GL_LINEAR);
1667
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (GLint) GL_LINEAR);
1668
_tmp6_ = cairo_image_surface_get_data (surface);
1669
gluBuild2DMipmaps (GL_TEXTURE_2D, (GLint) GL_ALPHA, (GLsizei) texture_width, (GLsizei) texture_height, GL_ALPHA, GL_UNSIGNED_BYTE, _tmp6_);
1671
_cairo_destroy0 (c);
1672
_cairo_surface_destroy0 (surface);
1677
static void chess_view3_d_draw_centered_text (ChessView3D* self, cairo_t* c, gdouble x, gdouble y, gdouble scale, const gchar* text) {
1678
cairo_text_extents_t extents = {0};
1679
cairo_text_extents_t _tmp0_ = {0};
1680
g_return_if_fail (self != NULL);
1681
g_return_if_fail (c != NULL);
1682
g_return_if_fail (text != NULL);
1683
cairo_text_extents (c, text, &_tmp0_);
1686
cairo_translate (c, x, y);
1687
cairo_move_to (c, ((-extents.width) * scale) / 2, (extents.height * scale) / 2);
1688
cairo_scale (c, scale, scale);
1689
cairo_show_text (c, text);
1694
static GLuint chess_view3_d_get_board_texture (ChessView3D* self) {
1696
g_return_val_if_fail (self != NULL, 0U);
1697
if (self->priv->_board_texture == 0) {
1698
gchar* _tmp0_ = NULL;
1701
_tmp0_ = g_build_filename (PKGDATADIR, "textures", "board.png", NULL, NULL);
1703
_tmp2_ = chess_view3_d_load_texture (self, _tmp1_);
1704
self->priv->_board_texture = _tmp2_;
1707
result = self->priv->_board_texture;
1712
static GLuint chess_view3_d_get_numbering_texture (ChessView3D* self) {
1714
g_return_val_if_fail (self != NULL, 0U);
1715
if (self->priv->_numbering_texture == 0) {
1717
_tmp0_ = chess_view3_d_make_numbering_texture (self);
1718
self->priv->_numbering_texture = _tmp0_;
1720
result = self->priv->_numbering_texture;
1725
static GLuint chess_view3_d_get_piece_texture (ChessView3D* self) {
1727
g_return_val_if_fail (self != NULL, 0U);
1728
if (self->priv->_piece_texture == 0) {
1729
gchar* _tmp0_ = NULL;
1732
_tmp0_ = g_build_filename (PKGDATADIR, "textures", "piece.png", NULL, NULL);
1734
_tmp2_ = chess_view3_d_load_texture (self, _tmp1_);
1735
self->priv->_piece_texture = _tmp2_;
1738
result = self->priv->_piece_texture;
1743
static void chess_view3_d_class_init (ChessView3DClass * klass) {
1744
chess_view3_d_parent_class = g_type_class_peek_parent (klass);
1745
g_type_class_add_private (klass, sizeof (ChessView3DPrivate));
1746
GTK_WIDGET_CLASS (klass)->configure_event = chess_view3_d_real_configure_event;
1747
GTK_WIDGET_CLASS (klass)->draw = chess_view3_d_real_draw;
1748
GTK_WIDGET_CLASS (klass)->button_press_event = chess_view3_d_real_button_press_event;
1749
G_OBJECT_CLASS (klass)->get_property = _vala_chess_view3_d_get_property;
1750
G_OBJECT_CLASS (klass)->finalize = chess_view3_d_finalize;
1754
static void chess_view3_d_instance_init (ChessView3D * self) {
1755
self->priv = CHESS_VIEW3_D_GET_PRIVATE (self);
1756
self->priv->context = (GLXContext) NULL;
1757
self->priv->border = 6;
1758
self->priv->_board_texture = (GLuint) 0;
1759
self->priv->_numbering_texture = (GLuint) 0;
1760
self->priv->_piece_texture = (GLuint) 0;
1764
static void chess_view3_d_finalize (GObject* obj) {
1766
self = CHESS_VIEW3_D (obj);
1767
_tds_model_unref0 (self->priv->pawn_model);
1768
_tds_model_unref0 (self->priv->knight_model);
1769
_tds_model_unref0 (self->priv->bishop_model);
1770
_tds_model_unref0 (self->priv->rook_model);
1771
_tds_model_unref0 (self->priv->queen_model);
1772
_tds_model_unref0 (self->priv->king_model);
1773
self->priv->board_vertices = (g_free (self->priv->board_vertices), NULL);
1774
self->priv->board_normals = (g_free (self->priv->board_normals), NULL);
1775
self->priv->board_quads = (g_free (self->priv->board_quads), NULL);
1776
G_OBJECT_CLASS (chess_view3_d_parent_class)->finalize (obj);
1780
GType chess_view3_d_get_type (void) {
1781
static volatile gsize chess_view3_d_type_id__volatile = 0;
1782
if (g_once_init_enter (&chess_view3_d_type_id__volatile)) {
1783
static const GTypeInfo g_define_type_info = { sizeof (ChessView3DClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) chess_view3_d_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ChessView3D), 0, (GInstanceInitFunc) chess_view3_d_instance_init, NULL };
1784
GType chess_view3_d_type_id;
1785
chess_view3_d_type_id = g_type_register_static (TYPE_CHESS_VIEW, "ChessView3D", &g_define_type_info, 0);
1786
g_once_init_leave (&chess_view3_d_type_id__volatile, chess_view3_d_type_id);
1788
return chess_view3_d_type_id__volatile;
1792
static void _vala_chess_view3_d_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
1794
self = CHESS_VIEW3_D (object);
1795
switch (property_id) {
1797
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);