~ubuntu-branches/ubuntu/precise/gnome-games/precise-proposed

« back to all changes in this revision

Viewing changes to glchess/src/chess-view-3d.c

  • Committer: Package Import Robot
  • Author(s): Rodrigo Moya
  • Date: 2011-05-30 13:32:04 UTC
  • mfrom: (1.3.4)
  • mto: (163.1.3 precise)
  • mto: This revision was merged to the branch mainline in revision 143.
  • Revision ID: package-import@ubuntu.com-20110530133204-celaq1v1dsxc48q1
Tags: upstream-3.0.2
ImportĀ upstreamĀ versionĀ 3.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* chess-view-3d.c generated by valac 0.12.0, the Vala compiler
 
2
 * generated from chess-view-3d.vala, do not modify */
 
3
 
 
4
 
 
5
#include <glib.h>
 
6
#include <glib-object.h>
 
7
#include <gtk/gtk.h>
 
8
#include <GL/glx.h>
 
9
#include <GL/gl.h>
 
10
#include <gdk/gdk.h>
 
11
#include <string.h>
 
12
#include <gio/gio.h>
 
13
#include <config.h>
 
14
#include <float.h>
 
15
#include <math.h>
 
16
#include <gdk/gdkx.h>
 
17
#include <X11/Xlib.h>
 
18
#include <X11/Xatom.h>
 
19
#include <X11/Xutil.h>
 
20
#include <X11/Xregion.h>
 
21
#include <cairo.h>
 
22
#include <GL/glu.h>
 
23
#include <stdlib.h>
 
24
#include <gdk-pixbuf/gdk-pixdata.h>
 
25
 
 
26
 
 
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))
 
33
 
 
34
typedef struct _ChessView ChessView;
 
35
typedef struct _ChessViewClass ChessViewClass;
 
36
typedef struct _ChessViewPrivate ChessViewPrivate;
 
37
 
 
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))
 
44
 
 
45
typedef struct _ChessView3D ChessView3D;
 
46
typedef struct _ChessView3DClass ChessView3DClass;
 
47
typedef struct _ChessView3DPrivate ChessView3DPrivate;
 
48
 
 
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))
 
55
 
 
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)))
 
63
 
 
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))
 
70
 
 
71
typedef struct _ChessScene ChessScene;
 
72
typedef struct _ChessSceneClass ChessSceneClass;
 
73
 
 
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))
 
80
 
 
81
typedef struct _ChessGame ChessGame;
 
82
typedef struct _ChessGameClass ChessGameClass;
 
83
typedef struct _ChessScenePrivate ChessScenePrivate;
 
84
 
 
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))
 
91
 
 
92
typedef struct _ChessModel ChessModel;
 
93
typedef struct _ChessModelClass ChessModelClass;
 
94
typedef struct _ChessModelPrivate ChessModelPrivate;
 
95
 
 
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))
 
102
 
 
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;
 
108
 
 
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))
 
115
 
 
116
typedef struct _ChessPlayer ChessPlayer;
 
117
typedef struct _ChessPlayerClass ChessPlayerClass;
 
118
 
 
119
#define TYPE_PIECE_TYPE (piece_type_get_type ())
 
120
typedef struct _ChessPlayerPrivate ChessPlayerPrivate;
 
121
 
 
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)))
 
125
 
 
126
struct _ChessView {
 
127
        GtkDrawingArea parent_instance;
 
128
        ChessViewPrivate * priv;
 
129
};
 
130
 
 
131
struct _ChessViewClass {
 
132
        GtkDrawingAreaClass parent_class;
 
133
};
 
134
 
 
135
struct _ChessView3D {
 
136
        ChessView parent_instance;
 
137
        ChessView3DPrivate * priv;
 
138
};
 
139
 
 
140
struct _ChessView3DClass {
 
141
        ChessViewClass parent_class;
 
142
};
 
143
 
 
144
struct _ChessView3DPrivate {
 
145
        GLXContext context;
 
146
        void* display;
 
147
        GLXDrawable drawable;
 
148
        gint border;
 
149
        gint square_size;
 
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;
 
166
        GLfloat BOARD_DEPTH;
 
167
        GLfloat BOARD_BORDER;
 
168
        GLfloat BOARD_CHAMFER;
 
169
        GLfloat BOARD_INNER_WIDTH;
 
170
        GLfloat BOARD_OUTER_WIDTH;
 
171
        GLfloat OFFSET;
 
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;
 
179
};
 
180
 
 
181
struct _ChessScene {
 
182
        GObject parent_instance;
 
183
        ChessScenePrivate * priv;
 
184
        GList* pieces;
 
185
        gboolean animating;
 
186
        gint selected_rank;
 
187
        gint selected_file;
 
188
};
 
189
 
 
190
struct _ChessSceneClass {
 
191
        GObjectClass parent_class;
 
192
};
 
193
 
 
194
struct _ChessModel {
 
195
        GTypeInstance parent_instance;
 
196
        volatile int ref_count;
 
197
        ChessModelPrivate * priv;
 
198
        ChessPiece* piece;
 
199
        gdouble x;
 
200
        gdouble y;
 
201
        gdouble target_x;
 
202
        gdouble target_y;
 
203
        gboolean under_threat;
 
204
        gboolean is_selected;
 
205
};
 
206
 
 
207
struct _ChessModelClass {
 
208
        GTypeClass parent_class;
 
209
        void (*finalize) (ChessModel *self);
 
210
};
 
211
 
 
212
typedef enum  {
 
213
        PIECE_TYPE_PAWN,
 
214
        PIECE_TYPE_ROOK,
 
215
        PIECE_TYPE_KNIGHT,
 
216
        PIECE_TYPE_BISHOP,
 
217
        PIECE_TYPE_QUEEN,
 
218
        PIECE_TYPE_KING
 
219
} PieceType;
 
220
 
 
221
struct _ChessPiece {
 
222
        GTypeInstance parent_instance;
 
223
        volatile int ref_count;
 
224
        ChessPiecePrivate * priv;
 
225
        ChessPlayer* player;
 
226
        PieceType type;
 
227
};
 
228
 
 
229
struct _ChessPieceClass {
 
230
        GTypeClass parent_class;
 
231
        void (*finalize) (ChessPiece *self);
 
232
};
 
233
 
 
234
typedef enum  {
 
235
        COLOR_WHITE,
 
236
        COLOR_BLACK
 
237
} Color;
 
238
 
 
239
struct _ChessPlayer {
 
240
        GObject parent_instance;
 
241
        ChessPlayerPrivate * priv;
 
242
        Color color;
 
243
};
 
244
 
 
245
struct _ChessPlayerClass {
 
246
        GObjectClass parent_class;
 
247
};
 
248
 
 
249
 
 
250
static gpointer chess_view3_d_parent_class = NULL;
 
251
 
 
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))
 
262
enum  {
 
263
        CHESS_VIEW3_D_DUMMY_PROPERTY
 
264
};
 
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);
 
331
 
 
332
 
 
333
static void _chess_view3_d_realize_cb_gtk_widget_realize (GtkWidget* _sender, gpointer self) {
 
334
        chess_view3_d_realize_cb (self);
 
335
}
 
336
 
 
337
 
 
338
static void _chess_view3_d_unrealize_cb_gtk_widget_unrealize (GtkWidget* _sender, gpointer self) {
 
339
        chess_view3_d_unrealize_cb (self);
 
340
}
 
341
 
 
342
 
 
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;
 
350
        gchar* _tmp5_;
 
351
        GFile* _tmp6_ = NULL;
 
352
        GFile* _tmp7_;
 
353
        TDSModel* _tmp8_ = NULL;
 
354
        TDSModel* _tmp9_;
 
355
        TDSModel* _tmp10_;
 
356
        gchar* _tmp11_ = NULL;
 
357
        gchar* _tmp12_;
 
358
        GFile* _tmp13_ = NULL;
 
359
        GFile* _tmp14_;
 
360
        TDSModel* _tmp15_ = NULL;
 
361
        TDSModel* _tmp16_;
 
362
        TDSModel* _tmp17_;
 
363
        gchar* _tmp18_ = NULL;
 
364
        gchar* _tmp19_;
 
365
        GFile* _tmp20_ = NULL;
 
366
        GFile* _tmp21_;
 
367
        TDSModel* _tmp22_ = NULL;
 
368
        TDSModel* _tmp23_;
 
369
        TDSModel* _tmp24_;
 
370
        gchar* _tmp25_ = NULL;
 
371
        gchar* _tmp26_;
 
372
        GFile* _tmp27_ = NULL;
 
373
        GFile* _tmp28_;
 
374
        TDSModel* _tmp29_ = NULL;
 
375
        TDSModel* _tmp30_;
 
376
        TDSModel* _tmp31_;
 
377
        gchar* _tmp32_ = NULL;
 
378
        gchar* _tmp33_;
 
379
        GFile* _tmp34_ = NULL;
 
380
        GFile* _tmp35_;
 
381
        TDSModel* _tmp36_ = NULL;
 
382
        TDSModel* _tmp37_;
 
383
        TDSModel* _tmp38_;
 
384
        gchar* _tmp39_ = NULL;
 
385
        gchar* _tmp40_;
 
386
        GFile* _tmp41_ = NULL;
 
387
        GFile* _tmp42_;
 
388
        TDSModel* _tmp43_ = NULL;
 
389
        TDSModel* _tmp44_;
 
390
        TDSModel* _tmp45_;
 
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);
 
425
        _tmp5_ = _tmp4_;
 
426
        _tmp6_ = g_file_new_for_path (_tmp5_);
 
427
        _tmp7_ = _tmp6_;
 
428
        _tmp8_ = tds_model_new (_tmp7_, &_inner_error_);
 
429
        _tmp9_ = _tmp8_;
 
430
        _g_object_unref0 (_tmp7_);
 
431
        _g_free0 (_tmp5_);
 
432
        _tmp10_ = _tmp9_;
 
433
        if (_inner_error_ != NULL) {
 
434
                goto __catch13_g_error;
 
435
        }
 
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);
 
439
        _tmp12_ = _tmp11_;
 
440
        _tmp13_ = g_file_new_for_path (_tmp12_);
 
441
        _tmp14_ = _tmp13_;
 
442
        _tmp15_ = tds_model_new (_tmp14_, &_inner_error_);
 
443
        _tmp16_ = _tmp15_;
 
444
        _g_object_unref0 (_tmp14_);
 
445
        _g_free0 (_tmp12_);
 
446
        _tmp17_ = _tmp16_;
 
447
        if (_inner_error_ != NULL) {
 
448
                goto __catch13_g_error;
 
449
        }
 
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);
 
453
        _tmp19_ = _tmp18_;
 
454
        _tmp20_ = g_file_new_for_path (_tmp19_);
 
455
        _tmp21_ = _tmp20_;
 
456
        _tmp22_ = tds_model_new (_tmp21_, &_inner_error_);
 
457
        _tmp23_ = _tmp22_;
 
458
        _g_object_unref0 (_tmp21_);
 
459
        _g_free0 (_tmp19_);
 
460
        _tmp24_ = _tmp23_;
 
461
        if (_inner_error_ != NULL) {
 
462
                goto __catch13_g_error;
 
463
        }
 
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);
 
467
        _tmp26_ = _tmp25_;
 
468
        _tmp27_ = g_file_new_for_path (_tmp26_);
 
469
        _tmp28_ = _tmp27_;
 
470
        _tmp29_ = tds_model_new (_tmp28_, &_inner_error_);
 
471
        _tmp30_ = _tmp29_;
 
472
        _g_object_unref0 (_tmp28_);
 
473
        _g_free0 (_tmp26_);
 
474
        _tmp31_ = _tmp30_;
 
475
        if (_inner_error_ != NULL) {
 
476
                goto __catch13_g_error;
 
477
        }
 
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);
 
481
        _tmp33_ = _tmp32_;
 
482
        _tmp34_ = g_file_new_for_path (_tmp33_);
 
483
        _tmp35_ = _tmp34_;
 
484
        _tmp36_ = tds_model_new (_tmp35_, &_inner_error_);
 
485
        _tmp37_ = _tmp36_;
 
486
        _g_object_unref0 (_tmp35_);
 
487
        _g_free0 (_tmp33_);
 
488
        _tmp38_ = _tmp37_;
 
489
        if (_inner_error_ != NULL) {
 
490
                goto __catch13_g_error;
 
491
        }
 
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);
 
495
        _tmp40_ = _tmp39_;
 
496
        _tmp41_ = g_file_new_for_path (_tmp40_);
 
497
        _tmp42_ = _tmp41_;
 
498
        _tmp43_ = tds_model_new (_tmp42_, &_inner_error_);
 
499
        _tmp44_ = _tmp43_;
 
500
        _g_object_unref0 (_tmp42_);
 
501
        _g_free0 (_tmp40_);
 
502
        _tmp45_ = _tmp44_;
 
503
        if (_inner_error_ != NULL) {
 
504
                goto __catch13_g_error;
 
505
        }
 
506
        _tds_model_unref0 (self->priv->king_model);
 
507
        self->priv->king_model = _tmp45_;
 
508
        goto __finally13;
 
509
        __catch13_g_error:
 
510
        {
 
511
                GError * e;
 
512
                e = _inner_error_;
 
513
                _inner_error_ = NULL;
 
514
                _g_error_free0 (e);
 
515
        }
 
516
        __finally13:
 
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_);
 
520
                return NULL;
 
521
        }
 
522
        chess_view3_d_create_board (self);
 
523
        return self;
 
524
}
 
525
 
 
526
 
 
527
ChessView3D* chess_view3_d_new (void) {
 
528
        return chess_view3_d_construct (TYPE_CHESS_VIEW3_D);
 
529
}
 
530
 
 
531
 
 
532
static gboolean _context_equal (const GLXContext* s1, const GLXContext* s2) {
 
533
        if (s1 == s2) {
 
534
                return TRUE;
 
535
        }
 
536
        if (s1 == NULL) {
 
537
                return FALSE;
 
538
        }
 
539
        if (s2 == NULL) {
 
540
                return FALSE;
 
541
        }
 
542
        return (*s1) == (*s2);
 
543
}
 
544
 
 
545
 
 
546
static gboolean chess_view3_d_start_gl (ChessView3D* self) {
 
547
        gboolean result = FALSE;
 
548
        GLXContext null_context;
 
549
        gboolean _tmp0_;
 
550
        g_return_val_if_fail (self != NULL, FALSE);
 
551
        null_context = (GLXContext) NULL;
 
552
        if (_context_equal (&self->priv->context, &null_context) == TRUE) {
 
553
                result = FALSE;
 
554
                return result;
 
555
        }
 
556
        _tmp0_ = glXMakeCurrent (self->priv->display, self->priv->drawable, self->priv->context);
 
557
        result = _tmp0_;
 
558
        return result;
 
559
}
 
560
 
 
561
 
 
562
static void chess_view3_d_create_board (ChessView3D* self) {
 
563
        gfloat a;
 
564
        GLfloat b;
 
565
        GLfloat c;
 
566
        GLfloat d;
 
567
        GLfloat e;
 
568
        GLfloat f;
 
569
        gfloat l;
 
570
        GLfloat k;
 
571
        GLfloat j;
 
572
        GLfloat i;
 
573
        GLfloat h;
 
574
        GLfloat g;
 
575
        GLfloat* _tmp0_ = NULL;
 
576
        GLfloat* _tmp1_ = NULL;
 
577
        GLushort* _tmp2_ = NULL;
 
578
        g_return_if_fail (self != NULL);
 
579
        a = 0.0f;
 
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;
 
585
        l = 0.0f;
 
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);
 
592
        _tmp0_[0] = c;
 
593
        _tmp0_[1] = (GLfloat) 0.0f;
 
594
        _tmp0_[2] = i;
 
595
        _tmp0_[3] = d;
 
596
        _tmp0_[4] = (GLfloat) 0.0f;
 
597
        _tmp0_[5] = i;
 
598
        _tmp0_[6] = d;
 
599
        _tmp0_[7] = (GLfloat) 0.0f;
 
600
        _tmp0_[8] = j;
 
601
        _tmp0_[9] = c;
 
602
        _tmp0_[10] = (GLfloat) 0.0f;
 
603
        _tmp0_[11] = j;
 
604
        _tmp0_[12] = b;
 
605
        _tmp0_[13] = (GLfloat) 0.0f;
 
606
        _tmp0_[14] = h;
 
607
        _tmp0_[15] = e;
 
608
        _tmp0_[16] = (GLfloat) 0.0f;
 
609
        _tmp0_[17] = h;
 
610
        _tmp0_[18] = e;
 
611
        _tmp0_[19] = (GLfloat) 0.0f;
 
612
        _tmp0_[20] = k;
 
613
        _tmp0_[21] = b;
 
614
        _tmp0_[22] = (GLfloat) 0.0f;
 
615
        _tmp0_[23] = k;
 
616
        _tmp0_[24] = (GLfloat) a;
 
617
        _tmp0_[25] = -self->priv->BOARD_CHAMFER;
 
618
        _tmp0_[26] = g;
 
619
        _tmp0_[27] = f;
 
620
        _tmp0_[28] = -self->priv->BOARD_CHAMFER;
 
621
        _tmp0_[29] = g;
 
622
        _tmp0_[30] = f;
 
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;
 
630
        _tmp0_[38] = g;
 
631
        _tmp0_[39] = f;
 
632
        _tmp0_[40] = -self->priv->BOARD_DEPTH;
 
633
        _tmp0_[41] = g;
 
634
        _tmp0_[42] = f;
 
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;
 
741
}
 
742
 
 
743
 
 
744
static void chess_view3_d_realize_cb (ChessView3D* self) {
 
745
        gint* _tmp0_ = NULL;
 
746
        gint* attributes;
 
747
        gint attributes_length1;
 
748
        gint _attributes_size_;
 
749
        GdkWindow* _tmp1_ = NULL;
 
750
        Window _tmp2_;
 
751
        GdkWindow* _tmp3_ = NULL;
 
752
        GdkDisplay* _tmp4_ = NULL;
 
753
        Display* _tmp5_ = NULL;
 
754
        GdkScreen* _tmp6_ = NULL;
 
755
        gint _tmp7_;
 
756
        gint screen;
 
757
        XVisualInfo* _tmp8_ = NULL;
 
758
        XVisualInfo* visual;
 
759
        g_return_if_fail (self != NULL);
 
760
        _tmp0_ = g_new0 (gint, 17);
 
761
        _tmp0_[0] = GLX_RGBA;
 
762
        _tmp0_[1] = GLX_RED_SIZE;
 
763
        _tmp0_[2] = 1;
 
764
        _tmp0_[3] = GLX_GREEN_SIZE;
 
765
        _tmp0_[4] = 1;
 
766
        _tmp0_[5] = GLX_BLUE_SIZE;
 
767
        _tmp0_[6] = 1;
 
768
        _tmp0_[7] = GLX_DOUBLEBUFFER;
 
769
        _tmp0_[8] = GLX_DEPTH_SIZE;
 
770
        _tmp0_[9] = 1;
 
771
        _tmp0_[10] = GLX_ACCUM_RED_SIZE;
 
772
        _tmp0_[11] = 1;
 
773
        _tmp0_[12] = GLX_ACCUM_GREEN_SIZE;
 
774
        _tmp0_[13] = 1;
 
775
        _tmp0_[14] = GLX_ACCUM_BLUE_SIZE;
 
776
        _tmp0_[15] = 1;
 
777
        _tmp0_[16] = 0;
 
778
        attributes = _tmp0_;
 
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_);
 
790
        screen = _tmp7_;
 
791
        _tmp8_ = glXChooseVisual (self->priv->display, screen, attributes);
 
792
        visual = _tmp8_;
 
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);
 
796
        } else {
 
797
                GLXContext _tmp9_;
 
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");
 
804
                }
 
805
        }
 
806
        _XFree0 (visual);
 
807
        attributes = (g_free (attributes), NULL);
 
808
}
 
809
 
 
810
 
 
811
static void chess_view3_d_unrealize_cb (ChessView3D* self) {
 
812
        GLXContext null_context;
 
813
        GLXDrawable _tmp0_;
 
814
        g_return_if_fail (self != NULL);
 
815
        null_context = (GLXContext) NULL;
 
816
        if (_context_equal (&self->priv->context, &null_context) == TRUE) {
 
817
                return;
 
818
        }
 
819
        _tmp0_ = glXGetCurrentDrawable ();
 
820
        if (self->priv->drawable == _tmp0_) {
 
821
                glXWaitGL ();
 
822
                glXMakeCurrent (self->priv->display, (GLXDrawable) None, (GLXContext) NULL);
 
823
        }
 
824
        glXDestroyContext (self->priv->display, self->priv->context);
 
825
}
 
826
 
 
827
 
 
828
static gboolean chess_view3_d_real_configure_event (GtkWidget* base, GdkEventConfigure* event) {
 
829
        ChessView3D * self;
 
830
        gboolean result = FALSE;
 
831
        gint _tmp0_;
 
832
        gint _tmp1_;
 
833
        gint _tmp2_;
 
834
        gint short_edge;
 
835
        gdouble _tmp3_;
 
836
        gboolean _tmp4_;
 
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_);
 
841
        short_edge = _tmp2_;
 
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);
 
845
        if (_tmp4_) {
 
846
                gint _tmp5_;
 
847
                gint _tmp6_;
 
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_);
 
851
        }
 
852
        result = TRUE;
 
853
        return result;
 
854
}
 
855
 
 
856
 
 
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) {
 
858
        GLfloat xwsize;
 
859
        GLfloat ywsize;
 
860
        gint _tmp0_;
 
861
        GLfloat dx;
 
862
        gint _tmp1_;
 
863
        GLfloat dy;
 
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);
 
873
}
 
874
 
 
875
 
 
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) {
 
877
        GLfloat fov2;
 
878
        gdouble _tmp0_;
 
879
        gdouble _tmp1_;
 
880
        GLfloat top;
 
881
        GLfloat bottom;
 
882
        GLfloat right;
 
883
        GLfloat left;
 
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_));
 
889
        bottom = -top;
 
890
        right = top * aspect;
 
891
        left = -right;
 
892
        chess_view3_d_accFrustum (self, left, right, bottom, top, near, far, pixdx, pixdy, eyedx, eyedy, focus);
 
893
}
 
894
 
 
895
 
 
896
static gboolean chess_view3_d_real_draw (GtkWidget* base, cairo_t* c) {
 
897
        ChessView3D * self;
 
898
        gboolean result = FALSE;
 
899
        GLfloat* _tmp0_ = NULL;
 
900
        GLfloat* jitters;
 
901
        gint jitters_length1;
 
902
        gint _jitters_size_;
 
903
        gboolean _tmp1_;
 
904
        gint n_passes;
 
905
        ChessScene* _tmp2_ = NULL;
 
906
        gboolean _tmp3_;
 
907
        ChessScene* _tmp18_ = NULL;
 
908
        gboolean _tmp19_;
 
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);
 
918
        jitters = _tmp0_;
 
919
        jitters_length1 = 6;
 
920
        _jitters_size_ = 6;
 
921
        _tmp1_ = chess_view3_d_start_gl (self);
 
922
        if (!_tmp1_) {
 
923
                result = TRUE;
 
924
                jitters = (g_free (jitters), NULL);
 
925
                return result;
 
926
        }
 
927
        n_passes = 1;
 
928
        _tmp2_ = chess_view_get_scene ((ChessView*) self);
 
929
        _tmp3_ = chess_scene_get_show_3d_smooth (_tmp2_);
 
930
        if (_tmp3_) {
 
931
                glClear ((GLbitfield) GL_ACCUM_BUFFER_BIT);
 
932
                n_passes = 3;
 
933
        }
 
934
        {
 
935
                gint i;
 
936
                i = 0;
 
937
                {
 
938
                        gboolean _tmp4_;
 
939
                        _tmp4_ = TRUE;
 
940
                        while (TRUE) {
 
941
                                GtkStyle* _tmp5_ = NULL;
 
942
                                GtkStateType _tmp6_;
 
943
                                GdkColor bg;
 
944
                                ChessScene* _tmp7_ = NULL;
 
945
                                gboolean _tmp8_;
 
946
                                GLfloat* _tmp13_ = NULL;
 
947
                                GLfloat* pos;
 
948
                                gint pos_length1;
 
949
                                gint _pos_size_;
 
950
                                ChessScene* _tmp14_ = NULL;
 
951
                                gdouble _tmp15_;
 
952
                                ChessScene* _tmp16_ = NULL;
 
953
                                gboolean _tmp17_;
 
954
                                if (!_tmp4_) {
 
955
                                        i++;
 
956
                                }
 
957
                                _tmp4_ = FALSE;
 
958
                                if (!(i < n_passes)) {
 
959
                                        break;
 
960
                                }
 
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);
 
968
                                glLoadIdentity ();
 
969
                                _tmp7_ = chess_view_get_scene ((ChessView*) self);
 
970
                                _tmp8_ = chess_scene_get_show_3d_smooth (_tmp7_);
 
971
                                if (_tmp8_) {
 
972
                                        gint _tmp9_;
 
973
                                        gint _tmp10_;
 
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);
 
977
                                } else {
 
978
                                        gint _tmp11_;
 
979
                                        gint _tmp12_;
 
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);
 
983
                                }
 
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;
 
991
                                pos = _tmp13_;
 
992
                                pos_length1 = 4;
 
993
                                _pos_size_ = 4;
 
994
                                glLightfv (GL_LIGHT0, GL_POSITION, pos);
 
995
                                glEnable (GL_LIGHTING);
 
996
                                glEnable (GL_LIGHT0);
 
997
                                glPushMatrix ();
 
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);
 
1005
                                glPopMatrix ();
 
1006
                                _tmp16_ = chess_view_get_scene ((ChessView*) self);
 
1007
                                _tmp17_ = chess_scene_get_show_3d_smooth (_tmp16_);
 
1008
                                if (_tmp17_) {
 
1009
                                        glAccum (GL_ACCUM, (GLfloat) (1.0f / n_passes));
 
1010
                                }
 
1011
                                pos = (g_free (pos), NULL);
 
1012
                        }
 
1013
                }
 
1014
        }
 
1015
        _tmp18_ = chess_view_get_scene ((ChessView*) self);
 
1016
        _tmp19_ = chess_scene_get_show_3d_smooth (_tmp18_);
 
1017
        if (_tmp19_) {
 
1018
                glAccum (GL_RETURN, (GLfloat) 1);
 
1019
        }
 
1020
        glXSwapBuffers (self->priv->display, self->priv->drawable);
 
1021
        result = TRUE;
 
1022
        jitters = (g_free (jitters), NULL);
 
1023
        return result;
 
1024
}
 
1025
 
 
1026
 
 
1027
static void chess_view3_d_draw_board (ChessView3D* self) {
 
1028
        GLuint _tmp1_;
 
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));
 
1032
        glBegin (GL_QUADS);
 
1033
        {
 
1034
                gint i;
 
1035
                i = 0;
 
1036
                {
 
1037
                        gboolean _tmp0_;
 
1038
                        _tmp0_ = TRUE;
 
1039
                        while (TRUE) {
 
1040
                                gint j;
 
1041
                                if (!_tmp0_) {
 
1042
                                        i = i + 5;
 
1043
                                }
 
1044
                                _tmp0_ = FALSE;
 
1045
                                if (!(i < self->priv->board_quads_length1)) {
 
1046
                                        break;
 
1047
                                }
 
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]);
 
1058
                        }
 
1059
                }
 
1060
        }
 
1061
        glEnd ();
 
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);
 
1066
        {
 
1067
                gint rank;
 
1068
                rank = 0;
 
1069
                {
 
1070
                        gboolean _tmp2_;
 
1071
                        _tmp2_ = TRUE;
 
1072
                        while (TRUE) {
 
1073
                                if (!_tmp2_) {
 
1074
                                        rank++;
 
1075
                                }
 
1076
                                _tmp2_ = FALSE;
 
1077
                                if (!(rank < 8)) {
 
1078
                                        break;
 
1079
                                }
 
1080
                                {
 
1081
                                        gint file;
 
1082
                                        file = 0;
 
1083
                                        {
 
1084
                                                gboolean _tmp3_;
 
1085
                                                _tmp3_ = TRUE;
 
1086
                                                while (TRUE) {
 
1087
                                                        GLfloat x0;
 
1088
                                                        GLfloat x1;
 
1089
                                                        GLfloat z0;
 
1090
                                                        GLfloat z1;
 
1091
                                                        if (!_tmp3_) {
 
1092
                                                                file++;
 
1093
                                                        }
 
1094
                                                        _tmp3_ = FALSE;
 
1095
                                                        if (!(file < 8)) {
 
1096
                                                                break;
 
1097
                                                        }
 
1098
                                                        if (((file + rank) % 2) == 0) {
 
1099
                                                                glColor3f ((GLfloat) (0xee / 255.f), (GLfloat) (0xee / 255.f), (GLfloat) (0xec / 255.f));
 
1100
                                                        } else {
 
1101
                                                                glColor3f ((GLfloat) (0xba / 255.f), (GLfloat) (0xbd / 255.f), (GLfloat) (0xb6 / 255.f));
 
1102
                                                        }
 
1103
                                                        glBegin (GL_QUADS);
 
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);
 
1116
                                                        glEnd ();
 
1117
                                                }
 
1118
                                        }
 
1119
                                }
 
1120
                        }
 
1121
                }
 
1122
        }
 
1123
        glDisable (GL_TEXTURE_2D);
 
1124
        glDisable (GL_COLOR_MATERIAL);
 
1125
}
 
1126
 
 
1127
 
 
1128
static void chess_view3_d_draw_numbering (ChessView3D* self) {
 
1129
        GLfloat text_width;
 
1130
        GLfloat text_offset;
 
1131
        GLfloat offset;
 
1132
        GLfloat white_z_offset;
 
1133
        GLfloat black_z_offset;
 
1134
        GLfloat left_offset;
 
1135
        GLfloat right_offset;
 
1136
        GLuint _tmp0_;
 
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);
 
1154
        {
 
1155
                gint i;
 
1156
                i = 0;
 
1157
                {
 
1158
                        gboolean _tmp1_;
 
1159
                        _tmp1_ = TRUE;
 
1160
                        while (TRUE) {
 
1161
                                if (!_tmp1_) {
 
1162
                                        i++;
 
1163
                                }
 
1164
                                _tmp1_ = FALSE;
 
1165
                                if (!(i < 8)) {
 
1166
                                        break;
 
1167
                                }
 
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;
 
1173
                        }
 
1174
                }
 
1175
        }
 
1176
        glDisable (GL_BLEND);
 
1177
        glDisable (GL_COLOR_MATERIAL);
 
1178
        glDisable (GL_TEXTURE_2D);
 
1179
}
 
1180
 
 
1181
 
 
1182
static void chess_view3_d_draw_label (ChessView3D* self, GLfloat x, GLfloat z, GLfloat width, gint cell) {
 
1183
        GLfloat w;
 
1184
        GLfloat l;
 
1185
        g_return_if_fail (self != NULL);
 
1186
        w = (GLfloat) (1.0f / 16);
 
1187
        l = (GLfloat) (cell / 16.0f);
 
1188
        glPushMatrix ();
 
1189
        glTranslatef (x, (GLfloat) 0.0f, z);
 
1190
        glBegin (GL_QUADS);
 
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);
 
1199
        glEnd ();
 
1200
        glPopMatrix ();
 
1201
}
 
1202
 
 
1203
 
 
1204
static gpointer _chess_model_ref0 (gpointer self) {
 
1205
        return self ? chess_model_ref (self) : NULL;
 
1206
}
 
1207
 
 
1208
 
 
1209
static void chess_view3_d_draw_pieces (ChessView3D* self) {
 
1210
        ChessScene* _tmp0_ = NULL;
 
1211
        ChessGame* _tmp1_ = NULL;
 
1212
        GLuint _tmp2_;
 
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) {
 
1218
                return;
 
1219
        }
 
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);
 
1225
        {
 
1226
                GList* model_collection;
 
1227
                GList* model_it;
 
1228
                model_collection = _tmp3_->pieces;
 
1229
                for (model_it = model_collection; model_it != NULL; model_it = model_it->next) {
 
1230
                        ChessModel* _tmp4_;
 
1231
                        ChessModel* model;
 
1232
                        _tmp4_ = _chess_model_ref0 ((ChessModel*) model_it->data);
 
1233
                        model = _tmp4_;
 
1234
                        {
 
1235
                                glPushMatrix ();
 
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);
 
1239
                                }
 
1240
                                chess_view3_d_render_piece (self, model->piece, (GLfloat) 1.0f);
 
1241
                                glPopMatrix ();
 
1242
                                _chess_model_unref0 (model);
 
1243
                        }
 
1244
                }
 
1245
        }
 
1246
        {
 
1247
                gint rank;
 
1248
                rank = 0;
 
1249
                {
 
1250
                        gboolean _tmp5_;
 
1251
                        _tmp5_ = TRUE;
 
1252
                        while (TRUE) {
 
1253
                                if (!_tmp5_) {
 
1254
                                        rank++;
 
1255
                                }
 
1256
                                _tmp5_ = FALSE;
 
1257
                                if (!(rank < 8)) {
 
1258
                                        break;
 
1259
                                }
 
1260
                                {
 
1261
                                        gint file;
 
1262
                                        file = 0;
 
1263
                                        {
 
1264
                                                gboolean _tmp6_;
 
1265
                                                _tmp6_ = TRUE;
 
1266
                                                while (TRUE) {
 
1267
                                                        gboolean _tmp7_ = FALSE;
 
1268
                                                        ChessScene* _tmp8_ = NULL;
 
1269
                                                        gboolean _tmp9_;
 
1270
                                                        if (!_tmp6_) {
 
1271
                                                                file++;
 
1272
                                                        }
 
1273
                                                        _tmp6_ = FALSE;
 
1274
                                                        if (!(file < 8)) {
 
1275
                                                                break;
 
1276
                                                        }
 
1277
                                                        _tmp8_ = chess_view_get_scene ((ChessView*) self);
 
1278
                                                        _tmp9_ = chess_scene_get_show_move_hints (_tmp8_);
 
1279
                                                        if (_tmp9_) {
 
1280
                                                                ChessScene* _tmp10_ = NULL;
 
1281
                                                                gboolean _tmp11_;
 
1282
                                                                _tmp10_ = chess_view_get_scene ((ChessView*) self);
 
1283
                                                                _tmp11_ = chess_scene_can_move (_tmp10_, rank, file);
 
1284
                                                                _tmp7_ = _tmp11_;
 
1285
                                                        } else {
 
1286
                                                                _tmp7_ = FALSE;
 
1287
                                                        }
 
1288
                                                        if (_tmp7_) {
 
1289
                                                                ChessScene* _tmp12_ = NULL;
 
1290
                                                                ChessPiece* _tmp13_ = NULL;
 
1291
                                                                ChessPiece* _tmp14_;
 
1292
                                                                glPushMatrix ();
 
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_);
 
1299
                                                                _tmp14_ = _tmp13_;
 
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);
 
1304
                                                                glPopMatrix ();
 
1305
                                                        }
 
1306
                                                }
 
1307
                                        }
 
1308
                                }
 
1309
                        }
 
1310
                }
 
1311
        }
 
1312
        glDisable (GL_TEXTURE_2D);
 
1313
}
 
1314
 
 
1315
 
 
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);
 
1325
        } else {
 
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);
 
1328
        }
 
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);
 
1333
        }
 
1334
        switch (piece->type) {
 
1335
                case PIECE_TYPE_PAWN:
 
1336
                {
 
1337
                        tds_model_render (self->priv->pawn_model);
 
1338
                        break;
 
1339
                }
 
1340
                case PIECE_TYPE_ROOK:
 
1341
                {
 
1342
                        tds_model_render (self->priv->rook_model);
 
1343
                        break;
 
1344
                }
 
1345
                case PIECE_TYPE_KNIGHT:
 
1346
                {
 
1347
                        tds_model_render (self->priv->knight_model);
 
1348
                        break;
 
1349
                }
 
1350
                case PIECE_TYPE_BISHOP:
 
1351
                {
 
1352
                        tds_model_render (self->priv->bishop_model);
 
1353
                        break;
 
1354
                }
 
1355
                case PIECE_TYPE_QUEEN:
 
1356
                {
 
1357
                        tds_model_render (self->priv->queen_model);
 
1358
                        break;
 
1359
                }
 
1360
                case PIECE_TYPE_KING:
 
1361
                {
 
1362
                        tds_model_render (self->priv->king_model);
 
1363
                        break;
 
1364
                }
 
1365
                default:
 
1366
                break;
 
1367
        }
 
1368
}
 
1369
 
 
1370
 
 
1371
static gboolean chess_view3_d_real_button_press_event (GtkWidget* base, GdkEventButton* event) {
 
1372
        ChessView3D * self;
 
1373
        gboolean result = FALSE;
 
1374
        gboolean _tmp0_ = FALSE;
 
1375
        ChessScene* _tmp1_ = NULL;
 
1376
        ChessGame* _tmp2_ = NULL;
 
1377
        gboolean _tmp3_;
 
1378
        GLuint buffer[20] = {0};
 
1379
        gint _tmp4_;
 
1380
        gint _tmp5_;
 
1381
        GLint* _tmp6_ = NULL;
 
1382
        GLint* viewport;
 
1383
        gint viewport_length1;
 
1384
        gint _viewport_size_;
 
1385
        gint _tmp7_;
 
1386
        gint _tmp8_;
 
1387
        gint _tmp9_;
 
1388
        ChessScene* _tmp10_ = NULL;
 
1389
        gdouble _tmp11_;
 
1390
        GLint _tmp14_;
 
1391
        GLint n_hits;
 
1392
        self = (ChessView3D*) base;
 
1393
        _tmp1_ = chess_view_get_scene ((ChessView*) self);
 
1394
        _tmp2_ = chess_scene_get_game (_tmp1_);
 
1395
        if (_tmp2_ == NULL) {
 
1396
                _tmp0_ = TRUE;
 
1397
        } else {
 
1398
                _tmp0_ = (*event).button != 1;
 
1399
        }
 
1400
        if (_tmp0_) {
 
1401
                result = FALSE;
 
1402
                return result;
 
1403
        }
 
1404
        _tmp3_ = chess_view3_d_start_gl (self);
 
1405
        if (!_tmp3_) {
 
1406
                result = TRUE;
 
1407
                return result;
 
1408
        }
 
1409
        glSelectBuffer ((GLsizei) 20, buffer);
 
1410
        glRenderMode (GL_SELECT);
 
1411
        glInitNames ();
 
1412
        glMatrixMode (GL_PROJECTION);
 
1413
        glLoadIdentity ();
 
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_;
 
1421
        viewport = _tmp6_;
 
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);
 
1430
        glLoadIdentity ();
 
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);
 
1436
        {
 
1437
                gint rank;
 
1438
                rank = 0;
 
1439
                {
 
1440
                        gboolean _tmp12_;
 
1441
                        _tmp12_ = TRUE;
 
1442
                        while (TRUE) {
 
1443
                                if (!_tmp12_) {
 
1444
                                        rank++;
 
1445
                                }
 
1446
                                _tmp12_ = FALSE;
 
1447
                                if (!(rank < 8)) {
 
1448
                                        break;
 
1449
                                }
 
1450
                                glPushName ((GLuint) rank);
 
1451
                                {
 
1452
                                        gint file;
 
1453
                                        file = 0;
 
1454
                                        {
 
1455
                                                gboolean _tmp13_;
 
1456
                                                _tmp13_ = TRUE;
 
1457
                                                while (TRUE) {
 
1458
                                                        GLfloat x0;
 
1459
                                                        GLfloat x1;
 
1460
                                                        GLfloat z0;
 
1461
                                                        GLfloat z1;
 
1462
                                                        if (!_tmp13_) {
 
1463
                                                                file++;
 
1464
                                                        }
 
1465
                                                        _tmp13_ = FALSE;
 
1466
                                                        if (!(file < 8)) {
 
1467
                                                                break;
 
1468
                                                        }
 
1469
                                                        glPushName ((GLuint) file);
 
1470
                                                        glBegin (GL_QUADS);
 
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);
 
1479
                                                        glEnd ();
 
1480
                                                        glPopName ();
 
1481
                                                }
 
1482
                                        }
 
1483
                                }
 
1484
                                glPopName ();
 
1485
                        }
 
1486
                }
 
1487
        }
 
1488
        glFlush ();
 
1489
        _tmp14_ = glRenderMode (GL_RENDER);
 
1490
        n_hits = _tmp14_;
 
1491
        if (n_hits > 0) {
 
1492
                GLuint rank;
 
1493
                GLuint file;
 
1494
                ChessScene* _tmp15_ = NULL;
 
1495
                rank = buffer[3];
 
1496
                file = buffer[4];
 
1497
                _tmp15_ = chess_view_get_scene ((ChessView*) self);
 
1498
                chess_scene_select_square (_tmp15_, (gint) file, (gint) rank);
 
1499
        }
 
1500
        result = TRUE;
 
1501
        viewport = (g_free (viewport), NULL);
 
1502
        return result;
 
1503
}
 
1504
 
 
1505
 
 
1506
static void chess_view3_d_transform_camera (ChessView3D* self) {
 
1507
        g_return_if_fail (self != NULL);
 
1508
        glLoadIdentity ();
 
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);
 
1510
}
 
1511
 
 
1512
 
 
1513
static GLuint chess_view3_d_load_texture (ChessView3D* self, const gchar* filename) {
 
1514
        GLuint result = 0U;
 
1515
        GdkPixbuf* pixbuf = NULL;
 
1516
        GdkPixbuf* _tmp0_ = NULL;
 
1517
        GdkPixbuf* _tmp1_;
 
1518
        GLenum format = 0U;
 
1519
        gint _tmp2_;
 
1520
        GLuint textures[1] = {0};
 
1521
        GLuint t;
 
1522
        gint _tmp5_;
 
1523
        gint _tmp6_;
 
1524
        gint _tmp7_;
 
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_);
 
1530
        _tmp1_ = _tmp0_;
 
1531
        if (_inner_error_ != NULL) {
 
1532
                goto __catch14_g_error;
 
1533
        }
 
1534
        _g_object_unref0 (pixbuf);
 
1535
        pixbuf = _tmp1_;
 
1536
        goto __finally14;
 
1537
        __catch14_g_error:
 
1538
        {
 
1539
                GError * e;
 
1540
                e = _inner_error_;
 
1541
                _inner_error_ = NULL;
 
1542
                g_warning ("chess-view-3d.vala:579: Error loading texture %s: %s", filename, e->message);
 
1543
                result = (GLuint) 0;
 
1544
                _g_error_free0 (e);
 
1545
                _g_object_unref0 (pixbuf);
 
1546
                return result;
 
1547
        }
 
1548
        __finally14:
 
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_);
 
1553
                return 0U;
 
1554
        }
 
1555
        _tmp2_ = gdk_pixbuf_get_n_channels (pixbuf);
 
1556
        if (_tmp2_ == 1) {
 
1557
                format = GL_LUMINANCE;
 
1558
        } else {
 
1559
                gint _tmp3_;
 
1560
                _tmp3_ = gdk_pixbuf_get_n_channels (pixbuf);
 
1561
                if (_tmp3_ == 3) {
 
1562
                        format = GL_RGB;
 
1563
                } else {
 
1564
                        gint _tmp4_;
 
1565
                        _tmp4_ = gdk_pixbuf_get_n_channels (pixbuf);
 
1566
                        if (_tmp4_ == 4) {
 
1567
                                format = GL_RGBA;
 
1568
                        } else {
 
1569
                                g_warning ("chess-view-3d.vala:592: Unknown format image");
 
1570
                                result = (GLuint) 0;
 
1571
                                _g_object_unref0 (pixbuf);
 
1572
                                return result;
 
1573
                        }
 
1574
                }
 
1575
        }
 
1576
        glGenTextures ((GLsizei) 1, textures);
 
1577
        t = textures[0];
 
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_);
 
1589
        result = t;
 
1590
        _g_object_unref0 (pixbuf);
 
1591
        return result;
 
1592
}
 
1593
 
 
1594
 
 
1595
static GLuint chess_view3_d_make_numbering_texture (ChessView3D* self) {
 
1596
        GLuint result = 0U;
 
1597
        gint width;
 
1598
        gint height;
 
1599
        gint texture_width;
 
1600
        gint texture_height;
 
1601
        cairo_surface_t* _tmp0_ = NULL;
 
1602
        cairo_surface_t* surface;
 
1603
        cairo_t* _tmp1_ = NULL;
 
1604
        cairo_t* c;
 
1605
        cairo_font_extents_t extents = {0};
 
1606
        cairo_font_extents_t _tmp2_ = {0};
 
1607
        gdouble scale;
 
1608
        gdouble yoffset;
 
1609
        gdouble xoffset;
 
1610
        GLuint textures[1] = {0};
 
1611
        GLuint t;
 
1612
        guchar* _tmp6_ = NULL;
 
1613
        g_return_val_if_fail (self != NULL, 0U);
 
1614
        width = 64;
 
1615
        height = 64;
 
1616
        texture_width = width * 16;
 
1617
        texture_height = height;
 
1618
        _tmp0_ = cairo_image_surface_create (CAIRO_FORMAT_A8, texture_width, texture_height);
 
1619
        surface = _tmp0_;
 
1620
        _tmp1_ = cairo_create (surface);
 
1621
        c = _tmp1_;
 
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_);
 
1626
        extents = _tmp2_;
 
1627
        scale = width / (extents.ascent + extents.descent);
 
1628
        yoffset = height * 0.5;
 
1629
        xoffset = width * 0.5;
 
1630
        {
 
1631
                gint i;
 
1632
                i = 0;
 
1633
                {
 
1634
                        gboolean _tmp3_;
 
1635
                        _tmp3_ = TRUE;
 
1636
                        while (TRUE) {
 
1637
                                gchar* _tmp4_ = NULL;
 
1638
                                gchar* f;
 
1639
                                gchar* _tmp5_ = NULL;
 
1640
                                gchar* r;
 
1641
                                if (!_tmp3_) {
 
1642
                                        i++;
 
1643
                                }
 
1644
                                _tmp3_ = FALSE;
 
1645
                                if (!(i < 8)) {
 
1646
                                        break;
 
1647
                                }
 
1648
                                _tmp4_ = g_strdup_printf ("%c", 'a' + i);
 
1649
                                f = _tmp4_;
 
1650
                                _tmp5_ = g_strdup_printf ("%c", '1' + i);
 
1651
                                r = _tmp5_;
 
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);
 
1655
                                _g_free0 (r);
 
1656
                                _g_free0 (f);
 
1657
                        }
 
1658
                }
 
1659
        }
 
1660
        glGenTextures ((GLsizei) 1, textures);
 
1661
        t = textures[0];
 
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_);
 
1670
        result = t;
 
1671
        _cairo_destroy0 (c);
 
1672
        _cairo_surface_destroy0 (surface);
 
1673
        return result;
 
1674
}
 
1675
 
 
1676
 
 
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_);
 
1684
        extents = _tmp0_;
 
1685
        cairo_save (c);
 
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);
 
1690
        cairo_restore (c);
 
1691
}
 
1692
 
 
1693
 
 
1694
static GLuint chess_view3_d_get_board_texture (ChessView3D* self) {
 
1695
        GLuint result;
 
1696
        g_return_val_if_fail (self != NULL, 0U);
 
1697
        if (self->priv->_board_texture == 0) {
 
1698
                gchar* _tmp0_ = NULL;
 
1699
                gchar* _tmp1_;
 
1700
                GLuint _tmp2_;
 
1701
                _tmp0_ = g_build_filename (PKGDATADIR, "textures", "board.png", NULL, NULL);
 
1702
                _tmp1_ = _tmp0_;
 
1703
                _tmp2_ = chess_view3_d_load_texture (self, _tmp1_);
 
1704
                self->priv->_board_texture = _tmp2_;
 
1705
                _g_free0 (_tmp1_);
 
1706
        }
 
1707
        result = self->priv->_board_texture;
 
1708
        return result;
 
1709
}
 
1710
 
 
1711
 
 
1712
static GLuint chess_view3_d_get_numbering_texture (ChessView3D* self) {
 
1713
        GLuint result;
 
1714
        g_return_val_if_fail (self != NULL, 0U);
 
1715
        if (self->priv->_numbering_texture == 0) {
 
1716
                GLuint _tmp0_;
 
1717
                _tmp0_ = chess_view3_d_make_numbering_texture (self);
 
1718
                self->priv->_numbering_texture = _tmp0_;
 
1719
        }
 
1720
        result = self->priv->_numbering_texture;
 
1721
        return result;
 
1722
}
 
1723
 
 
1724
 
 
1725
static GLuint chess_view3_d_get_piece_texture (ChessView3D* self) {
 
1726
        GLuint result;
 
1727
        g_return_val_if_fail (self != NULL, 0U);
 
1728
        if (self->priv->_piece_texture == 0) {
 
1729
                gchar* _tmp0_ = NULL;
 
1730
                gchar* _tmp1_;
 
1731
                GLuint _tmp2_;
 
1732
                _tmp0_ = g_build_filename (PKGDATADIR, "textures", "piece.png", NULL, NULL);
 
1733
                _tmp1_ = _tmp0_;
 
1734
                _tmp2_ = chess_view3_d_load_texture (self, _tmp1_);
 
1735
                self->priv->_piece_texture = _tmp2_;
 
1736
                _g_free0 (_tmp1_);
 
1737
        }
 
1738
        result = self->priv->_piece_texture;
 
1739
        return result;
 
1740
}
 
1741
 
 
1742
 
 
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;
 
1751
}
 
1752
 
 
1753
 
 
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;
 
1761
}
 
1762
 
 
1763
 
 
1764
static void chess_view3_d_finalize (GObject* obj) {
 
1765
        ChessView3D * self;
 
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);
 
1777
}
 
1778
 
 
1779
 
 
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);
 
1787
        }
 
1788
        return chess_view3_d_type_id__volatile;
 
1789
}
 
1790
 
 
1791
 
 
1792
static void _vala_chess_view3_d_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
 
1793
        ChessView3D * self;
 
1794
        self = CHESS_VIEW3_D (object);
 
1795
        switch (property_id) {
 
1796
                default:
 
1797
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
1798
                break;
 
1799
        }
 
1800
}
 
1801
 
 
1802
 
 
1803