CwChessboard.h
Go to the documentation of this file.
1 // cwchessboard -- A GTK+ chessboard widget
2 //
3 // Copyright (C) 2006, 2008 Carlo Wood
4 //
5 // Carlo Wood, Run on IRC <carlo@alinoe.com>
6 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
7 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
8 //
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License
11 // as published by the Free Software Foundation; either version 2
12 // of the License, or (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 
23 //! @file CwChessboard.h
24 //! @brief This file contains the declaration of the GTK+ widget %CwChessboard.
25 //! @image html arrowsandmarkers.png
26 
27 #ifndef CWCHESSBOARD_H
28 #define CWCHESSBOARD_H
29 
30 #include <math.h>
31 #include <glib.h>
32 #include <gtk/gtkdrawingarea.h>
33 
34 #ifdef __cplusplus
35 #define CWCHESSBOARD_INLINE inline
36 #define CWCHESSBOARD_DEFINE_INLINE 1
37 #else
38 #define CWCHESSBOARD_INLINE
39 #ifndef CWCHESSBOARD_DEFINE_INLINE
40 #define CWCHESSBOARD_DEFINE_INLINE 0
41 #endif
42 #endif
43 
44 G_BEGIN_DECLS
45 
46 #ifdef __cplusplus
47 #include <stdint.h>
48 typedef uint16_t CwChessboardCode;
49 #else
50 #include "CwChessboardCodes.h"
51 #endif
52 
53 GType cw_chessboard_get_type(void) G_GNUC_CONST;
54 
55 #define CW_TYPE_CHESSBOARD (cw_chessboard_get_type())
56 #define CW_CHESSBOARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CW_TYPE_CHESSBOARD, CwChessboard))
57 #define CW_CHESSBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CW_TYPE_CHESSBOARD, CwChessboardClass))
58 #define CW_IS_CHESSBOARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CW_TYPE_CHESSBOARD))
59 #define CW_IS_CHESSBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CW_TYPE_CHESSBOARD))
60 #define CW_CHESSBOARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CW_TYPE_CHESSBOARD, CwChessboardClass))
61 
62 typedef struct _CwChessboard CwChessboard;
63 typedef struct _CwChessboardClass CwChessboardClass;
65 
66 /** @typedef CwChessboardColorHandle
67  * @brief A color handle used for background markers.
68 *
69  * The five least significant bits determine the color
70  * from a user defined color palet, used by the background squares
71  * and markers. A value of zero meaning the default background value
72  * for that square, or no marker - respectively.
73 *
74  * @sa cw_chessboard_allocate_color_handle_rgb, cw_chessboard_allocate_color_handle, cw_chessboard_free_color_handle,
75  * cw_chessboard_set_background_color, cw_chessboard_get_background_color,
76  * cw_chessboard_set_background_colors, cw_chessboard_get_background_colors,
77  * cw_chessboard_set_marker_color, cw_chessboard_get_marker_color
78 * /
79 typedef unsigned char CwChessboardColorHandle;
80 
81 /** @name Creation* /
82 //@{
83 
84 /**
85  * Create a new chessboard widget.
86 *
87  * @returns Newly created CwChessboard.
88 * /
89 GtkWidget* cw_chessboard_new(void);
90 
91 //@} Creation
92 
93 #ifdef DOXYGEN
94 /** @struct CwChessboard
95  * @brief A GTK+ chessboard widget.
96 *
97  * This is a GTK+ widget. For a gtkmm widget, see cwmm::ChessboardWidget.
98 *
99  * @sa cw_chessboard_new
100 * /
102 #else
103 struct _CwChessboard
104 #endif
105 {
106  GtkDrawingArea parent;
107  CwChessboardPrivate* priv;
108 
109  //! Square side in pixels (read only).
110  gint const sside;
111  //! The x coordinate of the top-left pixel of square a1 (read-only). Despite the name, if the board is flipped then it's square h8.
112  gint const top_left_a1_x;
113  //! The y coordinate of the top-left pixel of square a1 (read-only). Despite the name, if the board is flipped then it's square h8.
114  gint const top_left_a1_y;
115  //! TRUE if the board is flipped (read-only).
116  gboolean const flip_board;
117 
118  void* gtkmm_widget; // This is for use by the gtkmm class ChessboardWidget, so don't use it.
119 };
120 
121 #ifdef DOXYGEN
122 /** @struct CwChessboardClass
123  * @brief The Class structure of %CwChessboard
124 * /
126 #else
127 struct _CwChessboardClass
128 #endif
129 {
130  GtkDrawingAreaClass parent_class;
131 
132  /** @name Virtual functions of CwChessboard* /
133  //@{
134 
135  /**
136  * Calculate the border width of the chessboard as function of the side of a square, in pixels.
137  *
138  * This function must use the parameter \a sside being passed and <em>not</em>
139  * the current sside of the passed \a chessboard (which can still be undefined even).
140  * The main reason for this is that sside recursively depends on the result of
141  * this function; it is called multiple times until sside stops changing and
142  * only then the real sside is set to it's final value.
143  *
144  * @param chessboard A #CwChessboard.
145  * @param sside The size of one side of a square.
146  *
147  * @returns The width of the border in pixels.
148  *
149  * Default value: #cw_chessboard_default_calc_board_border_width
150  * /
151  gint (*calc_board_border_width)(CwChessboard const* chessboard, gint sside);
152 
153  /**
154  * Draw the border around the chessboard.
155  * This function is called when the border is first drawn,
156  * and every time the chessboard is resized.
157  *
158  * The width of the drawn border should be the value returned by #calc_board_border_width.
159  *
160  * @param chessboard A #CwChessboard.
161  *
162  * Default value: #cw_chessboard_default_draw_border
163  *
164  * @sa cw_chessboard_set_draw_border
165  * /
166  void (*draw_border)(CwChessboard* chessboard);
167 
168  /**
169  * Draw the indicator that indicates whose turn it is.
170  * This function is called every time the border is redrawn,
171  * as well as every time #cw_chessboard_set_draw_turn_indicators
172  * is called.
173  *
174  * @param chessboard A #CwChessboard.
175  * @param white True if the indicator of the white color has to be drawn.
176  * @param on True if the indictor is on, false if it is off.
177  *
178  * Default value: #cw_chessboard_default_draw_turn_indicator
179  *
180  * @sa cw_chessboard_set_draw_border, cw_chessboard_set_draw_turn_indicators
181  * /
182  void (*draw_turn_indicator)(CwChessboard* chessboard, gboolean white, gboolean on);
183 
184  /**
185  * An array with function pointers for drawing chess pieces.
186  *
187  * The functions draw one of the six chess pieces, both white and black.
188  * The index of the array refers to the piece being drawn:
189  * pawn = 0, rook = 1, bishop = 2, knight = 3, queen = 4, king = 5.
190  *
191  * The default values are given below.
192  * They can be overridden by assigning other values to this array.
193  *
194  * \sa cw_chessboard_draw_pawn,
195  * cw_chessboard_draw_rook,
196  * cw_chessboard_draw_bishop,
197  * cw_chessboard_draw_knight,
198  * cw_chessboard_draw_queen,
199  * cw_chessboard_draw_king
200  * /
201  void (*draw_piece[6])(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white);
202 
203  /**
204  * Draw the HUD layer. This is a layer in between the background
205  * (existing of the 64 squares with a single color) and the layer
206  * with the pieces. It can be used to add some texture to the
207  * background.
208  *
209  * If the HUD layer is active, then this function is called
210  * whenever the widget is resized.
211  *
212  * @param chessboard A #CwChessboard.
213  * @param cr A cairo drawing context.
214  * @param sside The size of one side of a square, in pixels.
215  * @param hud The HUD index number, see the detailed documentation on the \ref index "main page" for more info.
216  *
217  * Default value: #cw_chessboard_default_draw_hud_layer
218  *
219  * @sa cw_chessboard_enable_hud_layer,
220  * cw_chessboard_disable_hud_layer,
221  * cw_chessboard_default_draw_hud_layer
222  * /
223  void (*draw_hud_layer)(CwChessboard* chessboard, cairo_t* cr, gint sside, guint hud);
224 
225  /**
226  * Draw a single HUD square at \a col, \a row.
227  * This function is called by cw_chessboard_default_draw_hud_layer
228  * for each square. You can use it if you don't override draw_hud_layer.
229  *
230  * @param chessboard A #CwChessboard.
231  * @param cr A cairo drawing context.
232  * @param col The column of the square.
233  * @param row The row of the square.
234  * @param sside The size of one side of the square, in pixels.
235  * @param hud The HUD index number, see the detailed documentation of \ref index "main page" for more info.
236  *
237  * @returns TRUE if anything was drawn at all, FALSE if the HUD square is fully transparent.
238  * /
239  gboolean (*draw_hud_square)(CwChessboard* chessboard, cairo_t* cr, gint col, gint row, gint sside, guint hud);
240 
241  /**
242  * Notify the user that the mouse pointer left the chessboard.
243  *
244  * If non-NULL, this function is called every time the mouse pointer
245  * leaves the chessboard.
246  *
247  * Default value: NULL.
248  *
249  * @param chessboard A #CwChessboard.
250  * @param prev_col The column of the last square.
251  * @param prev_row The row of the last square.
252  * /
253  void (*cursor_left_chessboard)(CwChessboard* chessboard, gint prev_col, gint prev_row);
254 
255  /**
256  * Notify the user that the mouse pointer entered a different square.
257  *
258  * If non-NULL, this function is called every time the mouse pointer enters
259  * a new square, whether from outside the chessboard or from another square.
260  *
261  * Default value: NULL.
262  *
263  * @param chessboard A #CwChessboard.
264  * @param prev_col The column of the last square, or -1 if we entered from outside the chessboard.
265  * @param prev_row The row of the last square, or -1 if we entered from outside the chessboard.
266  * @param col The column of the entered square.
267  * @param row The row of the entered square.
268  * /
269  void (*cursor_entered_square)(CwChessboard* chessboard, gint prev_col, gint prev_row, gint col, gint row);
270 
271  //@}
272 
273 };
274 
275 /**
276  * Convert a (\a col, \a row) pair to the top-left coordinates of the corresponding square,
277  * relative to the top-left of the widget.
278 *
279  * @param chessboard A #CwChessboard.
280  * @param col A column, in the range [0, 7].
281  * @param row A row, in the range [0, 7].
282  * @param x A pointer to where the x-coordinate of the result will be written to.
283  * @param y A pointer to where the y-coordinate of the result will be written to.
284 * /
285 CWCHESSBOARD_INLINE
286 void cw_chessboard_colrow2xy(CwChessboard* chessboard, gint col, gint row, gint* x, gint* y)
287 #if CWCHESSBOARD_DEFINE_INLINE
288 {
289  * x = chessboard->top_left_a1_x + (chessboard->flip_board ? 7 - col : col) * chessboard->sside;
290  * y = chessboard->top_left_a1_y - (chessboard->flip_board ? 7 - row : row) * chessboard->sside;
291 }
292 #else
293 ;
294 #endif
295 
296 /**
297  * Convert an x-coordinate to the column number that it matches.
298  * If the x coordinate falls outside the board, then the returned value
299  * will be outside the range [0, 7].
300 *
301  * @param chessboard A #CwChessboard.
302  * @param x An x coordinate, relative to the left-side of the widget.
303 *
304  * @returns A column number.
305 * /
306 CWCHESSBOARD_INLINE
307 gint cw_chessboard_x2col(CwChessboard* chessboard, gdouble x)
308 #if CWCHESSBOARD_DEFINE_INLINE
309 {
310  gint xcol = (gint)floor((x - chessboard->top_left_a1_x) / chessboard->sside);
311  return (chessboard->flip_board ? 7 - xcol : xcol);
312 }
313 #else
314 ;
315 #endif
316 
317 /**
318  * Convert a y-coordinate to the row number that it matches.
319  * If the y coordinate falls outside the board, then the returned value
320  * will be outside the range [0, 7].
321 *
322  * @param chessboard A #CwChessboard.
323  * @param y A y coordinate, relative to the top-side of the widget.
324 *
325  * @returns A row number.
326 * /
327 CWCHESSBOARD_INLINE
328 gint cw_chessboard_y2row(CwChessboard* chessboard, gdouble y)
329 #if CWCHESSBOARD_DEFINE_INLINE
330 {
331  gint yrow = (gint)floor((chessboard->top_left_a1_y + chessboard->sside - 1 - y) / chessboard->sside);
332  return (chessboard->flip_board ? 7 - yrow : yrow);
333 }
334 #else
335 ;
336 #endif
337 
338 /** @name Chess Position* /
339 //@{
340 
341 /**
342  * Change or remove the piece on the square (\a col, \a row),
343  * by replacing the contents of the square with \a code.
344  * This does not change any other attribute of the square,
345  * like it's background color or marker.
346 *
347  * @param chessboard A #CwChessboard.
348  * @param col A column [0..7]
349  * @param row A row [0..7]
350  * @param code A #CwChessboardCode.
351 * /
352 void cw_chessboard_set_square(CwChessboard* chessboard, gint col, gint row, CwChessboardCode code);
353 
354 /**
355  * Get the chess piece code for the square at (\a col, \a row).
356 * /
357 CwChessboardCode cw_chessboard_get_square(CwChessboard* chessboard, gint col, gint row);
358 
359 //@} Chess Position
360 
361 /** @name Border* /
362 //@{
363 
364 /**
365  * Set the boolean which determines whether or not the chessboard widget
366  * draws a border around the chessboard. Default: TRUE (draw border).
367 *
368  * @param chessboard A #CwChessboard.
369  * @param draw Boolean, determining if the border should be drawn.
370 *
371  * @sa CwChessboardClass::calc_board_border_width, CwChessboardClass::draw_border
372 * /
373 void cw_chessboard_set_draw_border(CwChessboard* chessboard, gboolean draw);
374 
375 /**
376  * Set the boolean which determines whether or not to draw turn indicators.
377  * Indicators will only be drawn if also the border is drawn.
378  * Default: TRUE (draw indicators).
379 *
380  * @param chessboard A #CwChessboard.
381  * @param draw Boolean, determining if the indicators should be drawn.
382 *
383  * @sa cw_chessboard_set_draw_border, CwChessboardClass::draw_turn_indicator
384 * /
385 void cw_chessboard_set_draw_turn_indicators(CwChessboard* chessboard, gboolean draw);
386 
387 /**
388  * Set the boolean that detemines which turn indicator is active (blacks or whites).
389  * If drawing turn indicators is enabled and the color is changed then the old
390  * indicator is erased. If the turn indicators are disabled, nothing happens.
391 *
392  * @param chessboard A #CwChessboard.
393  * @param white TRUE if the white turn indicator should be on (and blacks off).
394 *
395  * @sa cw_chessboard_set_draw_turn_indicators
396 * /
398 
399 /**
400  * Set the boolean which determines whether white is playing bottom up or top down.
401  * Default: FALSE (white plays upwards).
402 *
403  * @param chessboard A #CwChessboard.
404  * @param flip Boolean, determining if white plays upwards or not.
405 * /
406 void cw_chessboard_set_flip_board(CwChessboard* chessboard, gboolean flip);
407 
408 /**
409  * Get the boolean that determines whether or not the chessboard widget draws a border around the chessboard.
410 *
411  * @param chessboard A #CwChessboard.
412 *
413  * @returns <code>TRUE</code> if the border is being drawn.
414 *
415  * @sa cw_chessboard_set_draw_border
416 * /
417 gboolean cw_chessboard_get_draw_border(CwChessboard* chessboard);
418 
419 /**
420  * Get the boolean that determines whether or not turn indicators are being drawn.
421 *
422  * @param chessboard A #CwChessboard.
423 *
424  * @returns <code>TRUE</code> if turn indicators are being drawn.
425 *
426  * @sa cw_chessboard_set_draw_turn_indicators
427 * /
429 
430 /**
431  * Get the boolean that detemines which turn indicator is active (blacks or whites).
432 *
433  * @param chessboard A #CwChessboard.
434 *
435  * @returns <code>TRUE</code> if whites turn indicator is active (independent on whether or not it is being drawn).
436 *
437  * @sa cw_chessboard_set_active_turn_indicator
438 * /
440 
441 /**
442  * Get the boolean which determines whether white is playing bottom up or top down.
443 *
444  * @param chessboard A #CwChessboard.
445 *
446  * @returns <code>FALSE</code> if white plays upwards and <code>TRUE</code> if white plays downwards.
447 *
448  * @sa cw_chessboard_set_flip_board
449 * /
450 gboolean cw_chessboard_get_flip_board(CwChessboard* chessboard);
451 
452 /**
453  * This is the default value of CwChessboardClass::calc_board_border_width.
454  * The formula used by this default function is MAX(8.0, round(1.0 + (sside - 12) / 25.0) + sside / 3.0).
455 *
456  * @param chessboard A #CwChessboard.
457  * @param sside The size of one side of a square in pixels.
458 *
459  * @returns The border width in pixels.
460 *
461  * @sa CwChessboardClass::calc_board_border_width
462 * /
464 
465 //@} The Border
466 
467 /** @name Colors* /
468 //@{
469 
470 /**
471  * Set the background color of the dark squares (a1, c1 etc).
472  * Default: light green.
473 *
474  * @param chessboard A #CwChessboard.
475  * @param color The new color of the dark squares.
476 * /
477 void cw_chessboard_set_dark_square_color(CwChessboard* chessboard, GdkColor const* color);
478 
479 /**
480  * Set the background color of the light squares (b1, d1 etc).
481  * Default: yellow/white.
482 *
483  * @param chessboard A #CwChessboard.
484  * @param color The new color of the light squares.
485 * /
486 void cw_chessboard_set_light_square_color(CwChessboard* chessboard, GdkColor const* color);
487 
488 /**
489  * Set the color of the border around the chessboard.
490 *
491  * @param chessboard A #CwChessboard.
492  * @param color The new color of the border.
493 *
494  * @sa cw_chessboard_get_border_color, cw_chessboard_set_draw_border
495 * /
496 void cw_chessboard_set_border_color(CwChessboard* chessboard, GdkColor const* color);
497 
498 /**
499  * Set the fill color of the white chess pieces.
500  * Default: white
501 *
502  * @param chessboard A #CwChessboard.
503  * @param color The new fill color of the white pieces.
504 * /
505 void cw_chessboard_set_white_fill_color(CwChessboard* chessboard, GdkColor const* color);
506 
507 /**
508  * Set the line color of the white chess pieces.
509  * Default: black
510 *
511  * @param chessboard A #CwChessboard.
512  * @param color The new line color of the white pieces.
513 * /
514 void cw_chessboard_set_white_line_color(CwChessboard* chessboard, GdkColor const* color);
515 
516 /**
517  * Set the fill color of the black chess pieces.
518  * Default: black
519 *
520  * @param chessboard A #CwChessboard.
521  * @param color The new fill color of the black pieces.
522 * /
523 void cw_chessboard_set_black_fill_color(CwChessboard* chessboard, GdkColor const* color);
524 
525 /**
526  * Set the line color of the black chess pieces.
527  * Default: white
528 *
529  * @param chessboard A #CwChessboard.
530  * @param color The new line color of the black pieces.
531 * /
532 void cw_chessboard_set_black_line_color(CwChessboard* chessboard, GdkColor const* color);
533 
534 /**
535  * Retrieve the current background color of the dark squares.
536 *
537  * @param chessboard A #CwChessboard.
538  * @param color Pointer to the output variable.
539 *
540  * @sa cw_chessboard_set_dark_square_color
541 * /
542 void cw_chessboard_get_dark_square_color(CwChessboard* chessboard, GdkColor* color);
543 
544 /**
545  * Retrieve the current background color of the light squares.
546 *
547  * @param chessboard A #CwChessboard.
548  * @param color Pointer to the output variable.
549 *
550  * @sa cw_chessboard_set_light_square_color
551 * /
552 void cw_chessboard_get_light_square_color(CwChessboard* chessboard, GdkColor* color);
553 
554 /**
555  * Retrieve the current color of the border around the chessboard.
556 *
557  * @param chessboard A #CwChessboard.
558  * @param color Pointer to the output variable.
559 *
560  * @sa cw_chessboard_set_border_color
561 * /
562 void cw_chessboard_get_border_color(CwChessboard* chessboard, GdkColor* color);
563 
564 /**
565  * Retrieve the current fill color of the white chess pieces.
566 *
567  * @param chessboard A #CwChessboard.
568  * @param color Pointer to the output variable.
569 *
570  * @sa cw_chessboard_set_white_fill_color
571 * /
572 void cw_chessboard_get_white_fill_color(CwChessboard* chessboard, GdkColor* color);
573 
574 /**
575  * Retrieve the current line color of the white chess pieces.
576 *
577  * @param chessboard A #CwChessboard.
578  * @param color Pointer to the output variable.
579 *
580  * @sa cw_chessboard_set_white_line_color
581 * /
582 void cw_chessboard_get_white_line_color(CwChessboard* chessboard, GdkColor* color);
583 
584 /**
585  * Retrieve the current fill color of the black chess pieces.
586 *
587  * @param chessboard A #CwChessboard.
588  * @param color Pointer to the output variable.
589 *
590  * @sa cw_chessboard_set_black_fill_color
591 * /
592 void cw_chessboard_get_black_fill_color(CwChessboard* chessboard, GdkColor* color);
593 
594 /**
595  * Retrieve the current line color of the black chess pieces.
596 *
597  * @param chessboard A #CwChessboard.
598  * @param color Pointer to the output variable.
599 *
600  * @sa cw_chessboard_set_black_line_color
601 * /
602 void cw_chessboard_get_black_line_color(CwChessboard* chessboard, GdkColor* color);
603 
604 /**
605  * Allocate a new CwChessboardColorHandle.
606  * Simultaneous, there can be at most 31 different colors.
607  * It is the responsibility of the user to free the colors if they are no longer used.
608 *
609  * @param chessboard A #CwChessboard.
610  * @param red The red component of the color in the range [0...1].
611  * @param green The green component of the color in the range [0...1].
612  * @param blue The blue component of the color in the range [0...1].
613 *
614  * @returns A color handle that can be used with #cw_chessboard_set_background_color and #cw_chessboard_set_marker_color.
615 *
616  * @sa cw_chessboard_allocate_color_handle, cw_chessboard_free_color_handle
617 * /
618 CwChessboardColorHandle cw_chessboard_allocate_color_handle_rgb(CwChessboard* chessboard,
619  gdouble red, gdouble green, gdouble blue);
620 
621 /**
622  * Allocate a new CwChessboardColorHandle.
623  * From more information, see #cw_chessboard_allocate_color_handle_rgb.
624 *
625  * @param chessboard A #CwChessboard.
626  * @param color The color to allocate.
627 *
628  * @returns A color handle that can be used with #cw_chessboard_set_background_color and #cw_chessboard_set_marker_color.
629 *
630  * @sa cw_chessboard_free_color_handle
631 * /
632 CWCHESSBOARD_INLINE
633 CwChessboardColorHandle cw_chessboard_allocate_color_handle(CwChessboard* chessboard, GdkColor const* color)
634 #if CWCHESSBOARD_DEFINE_INLINE
635 {
636  return cw_chessboard_allocate_color_handle_rgb(chessboard, color->red / 65535.0,
637  color->green / 65535.0, color->blue / 65535.0);
638 }
639 #else
640 ;
641 #endif
642 
643 /**
644  * Free up the color handle \a handle, so it can be reused.
645 *
646  * @param chessboard A #CwChessboard.
647  * @param handle A color handle as returned by cw_chessboard_allocate_color_handle_rgb or cw_chessboard_allocate_color_handle.
648 *
649  * @sa cw_chessboard_allocate_color_handle_rgb, cw_chessboard_allocate_color_handle
650 * /
651 void cw_chessboard_free_color_handle(CwChessboard* chessboard, CwChessboardColorHandle handle);
652 
653 /**
654  * Set the background color of the square at \a col, \a row.
655 *
656  * @param chessboard A #CwChessboard.
657  * @param col The column of the square.
658  * @param row The row of the square.
659  * @param handle A color handle as returned by #cw_chessboard_allocate_color_handle_rgb or
660  * #cw_chessboard_allocate_color_handle. A handle with a value of 0 means the
661  * default background color.
662 * /
663 void cw_chessboard_set_background_color(CwChessboard* chessboard, gint col, gint row, CwChessboardColorHandle handle);
664 
665 /**
666  * Convenience function.
667 *
668  * @param chessboard A #CwChessboard.
669  * @param col The column of the square.
670  * @param row The row of the square.
671 *
672  * @returns The handle that was passed to #cw_chessboard_set_background_color
673  * for this square, or 0 if the square is not associated with a color handle.
674 * /
675 CwChessboardColorHandle cw_chessboard_get_background_color(CwChessboard* chessboard, gint col, gint row);
676 
677 /**
678  * Set new background colors of any number of squares.
679 *
680  * @param chessboard A #CwChessboard.
681  * @param handles Array of 64 CwChessboardColorHandles.
682  * A handle with a value of 0 means the default background color.
683 * /
684 void cw_chessboard_set_background_colors(CwChessboard* chessboard, CwChessboardColorHandle const* handles);
685 
686 /**
687  * Fill the array \a handles with the current color handles.
688 *
689  * @param chessboard A #CwChessboard.
690  * @param handles The output array. Should be an array of 64 CwChessboardColorHandles.
691 * /
692 void cw_chessboard_get_background_colors(CwChessboard* chessboard, CwChessboardColorHandle* handles);
693 
694 //@} Colors
695 
696 /** @name Floating Pieces* /
697 //@{
698 
699 /**
700  * This function displays a chess piece with code \a code at widget coordinates (\a x, \a y).
701  * Half the side of a square will be subtracted from the coordinates passed, and
702  * the result truncated, in order to determine where to draw the top-left corner
703  * of the piece. The result is that (\a x, \a y) is more or less the center of the piece.
704 *
705  * Setting \a pointer_device will cause gdk_window_get_pointer to be called
706  * after the next redraw has finished. This is needed to receive the next motion
707  * notify event with GDK_POINTER_MOTION_HINT_MASK being used.
708 *
709  * There may only be one floating piece related the pointer device at a time.
710  * If there is already another floating piece related to the pointer device
711  * then the value of \a pointer_device is ignored.
712 *
713  * @param chessboard A #CwChessboard.
714  * @param code The code of the chess piece to be drawn.
715  * @param x The center x-coordinate of the piece.
716  * @param y The center y-coordinate of the piece.
717  * @param pointer_device Whether this piece is under the pointer device or not.
718 *
719  * @returns A handle that can be passed to each of the functions below.
720 *
721  * @sa cw_chessboard_get_floating_piece,
722  * cw_chessboard_remove_floating_piece,
723  * cw_chessboard_move_floating_piece
724 * /
726  CwChessboardCode code, gdouble x, gdouble y, gboolean pointer_device);
727 
728 /**
729  * Move a floating piece with handle \a handle to the new widget
730  * coordinates at (\a x, \a y). \a handle must be a handle as
731  * returned by #cw_chessboard_add_floating_piece.
732 *
733  * @param chessboard A #CwChessboard.
734  * @param handle The floating piece handle.
735  * @param x The new x coordinate.
736  * @param y The new y coordinate.
737 *
738  * @sa cw_chessboard_add_floating_piece
739 * /
740 void cw_chessboard_move_floating_piece(CwChessboard* chessboard, gint handle, gdouble x, gdouble y);
741 
742 /**
743  * Delete the floating piece with handle \a handle.
744  * \a handle must be a handle as returned by #cw_chessboard_add_floating_piece.
745 *
746  * @param chessboard A #CwChessboard.
747  * @param handle The floating piece handle.
748 * /
749 void cw_chessboard_remove_floating_piece(CwChessboard* chessboard, gint handle);
750 
751 /**
752  * Get the CwChessboardCode of the floating piece represented by \a handle.
753  * \a handle must be a handle as returned by #cw_chessboard_add_floating_piece.
754 *
755  * @param chessboard A #CwChessboard.
756  * @param handle The floating piece handle.
757 * /
759 
760 //@} Floating Pieces
761 
762 /** @name Default Drawing Functions* /
763 //@{
764 
765 /**
766  * This is the default function used by CwChessboard to draw pawns.
767 *
768  * If \a white is set, a white pawn will be drawn. Otherwise a black pawn.
769 *
770  * <code>cw_chessboard_draw_pawn</code> is the default function called
771  * via a call to CwChessboardClass::draw_piece.
772  * It is called every time the chessboard is resized.
773 *
774  * The function uses vector graphics (by doing direct calls to cairo),
775  * and is therefore capable of drawing the piece in any arbitrary size
776  * and uses anti-aliasing.
777 *
778  * @image html pawn.png
779 *
780  * @param chessboard A #CwChessboard.
781  * @param cr The cairo drawing context.
782  * @param x The (widget) x-coordinate of the center of the piece.
783  * @param y The (widget) y-coordinate of the center of the piece.
784  * @param sside The assumed side of a square, in pixels.
785  * <code>chessboard->sside</code> is ignored, so that
786  * this function can be used to draw pieces elsewhere with a different
787  * size than what is used on the chessboard.
788  * @param white A boolean that determines if a black or white piece is drawn.
789 * /
790 void cw_chessboard_draw_pawn(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white);
791 
792 /**
793  * This is the default function used by CwChessboard to draw a rook.
794 *
795  * @image html rook.png
796 *
797  * See #cw_chessboard_draw_pawn for more details.
798 * /
799 void cw_chessboard_draw_rook(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white);
800 
801 /**
802  * This is the default function used by CwChessboard to draw a knight.
803 *
804  * @image html knight.png
805 *
806  * See #cw_chessboard_draw_pawn for more details.
807 * /
808 void cw_chessboard_draw_knight(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white);
809 
810 /**
811  * This is the default function used by CwChessboard to draw a bishop.
812 *
813  * @image html bishop.png
814 *
815  * See #cw_chessboard_draw_pawn for more details.
816 * /
817 void cw_chessboard_draw_bishop(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white);
818 
819 /**
820  * This is the default function used by CwChessboard to draw a queen.
821 *
822  * @image html queen.png
823 *
824  * See #cw_chessboard_draw_pawn for more details.
825 * /
826 void cw_chessboard_draw_queen(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white);
827 
828 /**
829  * This is the default function used by CwChessboard to draw a king.
830 *
831  * @image html king.png
832 *
833  * See #cw_chessboard_draw_pawn for more details.
834 * /
835 void cw_chessboard_draw_king(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white);
836 
837 /**
838  * The default CwChessboardClass::draw_hud_layer function.
839  * You can restore the default behaviour with:
840  * \code
841  * CW_CHESSBOARD_GET_CLASS(chessboard)->draw_hud_layer = cw_chessboard_default_draw_hud_layer;
842  * \endcode
843 *
844  * @param chessboard A #CwChessboard.
845  * @param cr The cairo drawing context.
846  * @param sside The side of one square in pixels.
847  * @param hud The HUD layer (0 or 1).
848 *
849  * This function calls CwChessboardClass::draw_hud_square for every square.
850 * /
851 void cw_chessboard_default_draw_hud_layer(CwChessboard* chessboard, cairo_t* cr, gint sside, guint hud);
852 
853 /**
854  * The default CwChessboardClass::draw_hud_square function.
855  * This function is only used by cw_chessboard_default_draw_hud_layer.
856  * You can restore the default behaviour of cw_chessboard_default_draw_hud_layer with:
857  * \code
858  * CW_CHESSBOARD_GET_CLASS(chessboard)->draw_hud_square = cw_chessboard_default_draw_hud_square;
859  * \endcode
860 *
861  * This function hatches the dark squares with fine, diagonal lines.
862 *
863  * @param chessboard A #CwChessboard.
864  * @param cr The cairo drawing context.
865  * @param col The column of the square.
866  * @param row The row of the square.
867  * @param sside The side of one square in pixels.
868  * @param hud The HUD layer (0 or 1).
869 *
870  * @returns <code>TRUE</code> if anything was drawn. <code>FALSE</code> otherwise.
871 * /
873  cairo_t* cr, gint col, gint row, gint sside, guint hud);
874 
875 /**
876  * This is the default value of CwChessboardClass::draw_border.
877 *
878  * @param chessboard A #CwChessboard.
879 * /
881 
882 /**
883  * This is the default value of CwChessboardClass::draw_turn_indicator.
884 *
885  * @param chessboard A #CwChessboard.
886  * @param white TRUE if it's whites indicator.
887  * @param on TRUE if the indicator has to be drawn, FALSE if the indicator has to be removed.
888 * /
889 void cw_chessboard_default_draw_turn_indicator(CwChessboard* chessboard, gboolean white, gboolean on);
890 
891 //@} Default Virtual Functions
892 
893 /** @name HUD Layers* /
894 //@{
895 
896 /**
897  * Active a HUD layer.
898  * HUD 0 lays between the background and the pieces.
899  * HUD 1 lays above the pieces.
900  * A custom HUD layer can be created by setting CwChessboardClass::draw_hud_layer.
901 *
902  * @param chessboard A #CwChessboard.
903  * @param hud The HUD layer (0 or 1).
904 *
905  * @sa CwChessboardClass::draw_hud_layer, cw_chessboard_disable_hud_layer
906 * /
907 void cw_chessboard_enable_hud_layer(CwChessboard* chessboard, guint hud);
908 
909 /**
910  * Disable the HUD layer again. Used resources are returned to the system.
911 *
912  * @param chessboard A #CwChessboard.
913  * @param hud The HUD layer (0 or 1).
914 *
915  * @sa cw_chessboard_enable_hud_layer
916 * /
917 void cw_chessboard_disable_hud_layer(CwChessboard* chessboard, guint hud);
918 
919 //@} // HUD Layers
920 
921 /** @name Markers* /
922 //@{
923 
924 /**
925  * Add (or remove) a marker to the square at \a col, \a row.
926 *
927  * @param chessboard A #CwChessboard.
928  * @param col The column of the square.
929  * @param row The row of the square.
930  * @param mahandle A color handle as returned by #cw_chessboard_allocate_color_handle_rgb or
931  * #cw_chessboard_allocate_color_handle. A handle with a value of 0 means the
932  * default background color.
933 * /
935  gint col, gint row, CwChessboardColorHandle mahandle);
936 
937 /**
938  * Convenience function.
939 *
940  * @param chessboard A #CwChessboard.
941  * @param col The column of the square.
942  * @param row The row of the square.
943 *
944  * @returns The handle that was passed to #cw_chessboard_set_marker_color
945  * for this square, or 0 if the square doesn't have a marker.
946 * /
947 CwChessboardColorHandle cw_chessboard_get_marker_color(CwChessboard* chessboard, gint col, gint row);
948 
949 /**
950  * Set the marker thickness. This is a value between 0 and 0.5.
951 *
952  * @param chessboard A #CwChessboard.
953  * @param thickness The thickness of the marker as fraction of sside. Range [0...0.5]
954 *
955  * @sa cw_chessboard_get_marker_thickness
956 * /
957 void cw_chessboard_set_marker_thickness(CwChessboard* chessboard, gdouble thickness);
958 
959 /**
960  * Get the current marker thickness as fraction of sside.
961 *
962  * @param chessboard A #CwChessboard.
963 *
964  * @sa cw_chessboard_set_marker_thickness
965 * /
967 
968 /**
969  * Choose whether markers should be drawn below or above HUD layer 0.
970 *
971  * Markers can be drawn directly below or directly above HUD layer 0.
972 *
973  * @param chessboard A #CwChessboard.
974  * @param below TRUE when markers should be drawn below HUD layer 0.
975 * /
976 void cw_chessboard_set_marker_level(CwChessboard* chessboard, gboolean below);
977 
978 //@} Markers
979 
980 /** @name Cursor* /
981 //@{
982 
983 /**
984  * Show the cursor.
985 *
986  * This high-lights the square under the mouse by drawing a
987  * square with a configurable thickness and color.
988 *
989  * @param chessboard A #CwChessboard.
990 *
991  * @sa cw_chessboard_set_cursor_thickness, cw_chessboard_get_cursor_thickness
992 * /
993 void cw_chessboard_show_cursor(CwChessboard* chessboard);
994 
995 /**
996  * Hide the cursor.
997 *
998  * @param chessboard A #CwChessboard.
999 *
1000  * @sa cw_chessboard_show_cursor
1001 * /
1002 void cw_chessboard_hide_cursor(CwChessboard* chessboard);
1003 
1004 /**
1005  * Set the cursor thickness. This is a value between 0 and 0.5.
1006 *
1007  * @param chessboard A #CwChessboard.
1008  * @param thickness The thickness of the cursor as fraction of sside. Range [0...0.5]
1009 *
1010  * @sa cw_chessboard_get_cursor_thickness
1011 * /
1012 void cw_chessboard_set_cursor_thickness(CwChessboard* chessboard, gdouble thickness);
1013 
1014 /**
1015  * Get the current cursor thickness as fraction of sside.
1016 *
1017  * @param chessboard A #CwChessboard.
1018 *
1019  * @sa cw_chessboard_set_cursor_thickness
1020 * /
1022 
1023 /**
1024  * Set the color of the cursor.
1025 *
1026  * @param chessboard A #CwChessboard.
1027  * @param color The color to be used for the cursor.
1028 * /
1029 void cw_chessboard_set_cursor_color(CwChessboard* chessboard, GdkColor const* color);
1030 
1031 /**
1032  * Get the current cursor color.
1033 *
1034  * @param chessboard A #CwChessboard.
1035  * @param color Pointer to the output variable.
1036 * /
1037 void cw_chessboard_get_cursor_color(CwChessboard* chessboard, GdkColor* color);
1038 
1039 //@} Cursor
1040 
1041 /** @name Arrows* /
1042 //@{
1043 
1044 /**
1045  * Draw an arrow on the board.
1046 *
1047  * @param chessboard A #CwChessboard.
1048  * @param begin_col The column of the starting square.
1049  * @param begin_row The row of the starting square.
1050  * @param end_col The column of the ending square.
1051  * @param end_row The row of the ending square.
1052  * @param color The color to draw the arrow in.
1053 *
1054  * @returns A handle that can be used to remove the arrow again.
1055 *
1056  * @sa cw_chessboard_remove_arrow
1057 * /
1058 gpointer cw_chessboard_add_arrow(CwChessboard* chessboard,
1059  gint begin_col, gint begin_row, gint end_col, gint end_row, GdkColor const* color);
1060 
1061 /**
1062  * Remove a previously added arrow.
1063 *
1064  * @param chessboard A #CwChessboard.
1065  * @param ptr The arrow handle as returned by #cw_chessboard_add_arrow.
1066 * /
1067 void cw_chessboard_remove_arrow(CwChessboard* chessboard, gpointer ptr);
1068 
1069 //@} Arrows
1070 
1071 G_END_DECLS
1072 
1073 #endif // CWCHESSBOARD_H
void cw_chessboard_enable_hud_layer(CwChessboard* chessboard, guint hud)
void cw_chessboard_move_floating_piece(CwChessboard* chessboard, gint handle, gdouble x, gdouble y)
gboolean cw_chessboard_get_active_turn_indicator(CwChessboard* chessboard)
void cw_chessboard_set_white_line_color(CwChessboard* chessboard, GdkColor const* color)
void cw_chessboard_draw_bishop(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
void cw_chessboard_default_draw_turn_indicator(CwChessboard* chessboard, gboolean white, gboolean on)
void cw_chessboard_draw_rook(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
gint const sside
Square side in pixels (read only).
Definition: CwChessboard.h:110
uint16_t CwChessboardCode
A code to specify a chess piece.
void cw_chessboard_set_cursor_color(CwChessboard* chessboard, GdkColor const* color)
void cw_chessboard_remove_floating_piece(CwChessboard* chessboard, gint handle)
CwChessboardColorHandle cw_chessboard_get_background_color(CwChessboard* chessboard, gint col, gint row)
void cw_chessboard_set_marker_level(CwChessboard* chessboard, gboolean below)
ColorData const white
A constant representing the color white.
Definition: Color.h:55
CWCHESSBOARD_INLINE gint cw_chessboard_x2col(CwChessboard* chessboard, gdouble x)
void cw_chessboard_draw_queen(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
void cw_chessboard_set_flip_board(CwChessboard* chessboard, gboolean flip)
void cw_chessboard_remove_arrow(CwChessboard* chessboard, gpointer ptr)
void cw_chessboard_get_cursor_color(CwChessboard* chessboard, GdkColor* color)
void cw_chessboard_default_draw_hud_layer(CwChessboard* chessboard, cairo_t* cr, gint sside, guint hud)
void cw_chessboard_default_draw_border(CwChessboard* chessboard)
void cw_chessboard_set_black_fill_color(CwChessboard* chessboard, GdkColor const* color)
CWCHESSBOARD_INLINE gint cw_chessboard_y2row(CwChessboard* chessboard, gdouble y)
void cw_chessboard_set_background_color(CwChessboard* chessboard, gint col, gint row, CwChessboardColorHandle handle)
gpointer cw_chessboard_add_arrow(CwChessboard* chessboard, gint begin_col, gint begin_row, gint end_col, gint end_row, GdkColor const* color)
void cw_chessboard_set_black_line_color(CwChessboard* chessboard, GdkColor const* color)
GtkWidget * cw_chessboard_new(void)
void cw_chessboard_get_dark_square_color(CwChessboard* chessboard, GdkColor* color)
void cw_chessboard_set_draw_border(CwChessboard* chessboard, gboolean draw)
void cw_chessboard_disable_hud_layer(CwChessboard* chessboard, guint hud)
A GTK+ chessboard widget.
Definition: CwChessboard.h:101
void cw_chessboard_get_background_colors(CwChessboard* chessboard, CwChessboardColorHandle* handles)
void cw_chessboard_set_border_color(CwChessboard* chessboard, GdkColor const* color)
CwChessboardCode cw_chessboard_get_floating_piece(CwChessboard* chessboard, gint handle)
void cw_chessboard_get_white_fill_color(CwChessboard* chessboard, GdkColor* color)
gdouble cw_chessboard_get_cursor_thickness(CwChessboard* chessboard)
unsigned char CwChessboardColorHandle
A color handle used for background markers.
Definition: CwChessboard.h:79
CWCHESSBOARD_INLINE void cw_chessboard_colrow2xy(CwChessboard* chessboard, gint col, gint row, gint* x, gint* y)
The Class structure of CwChessboard.
Definition: CwChessboard.h:125
void cw_chessboard_get_black_line_color(CwChessboard* chessboard, GdkColor* color)
gint cw_chessboard_default_calc_board_border_width(CwChessboard const* chessboard, gint sside)
gint const top_left_a1_y
The y coordinate of the top-left pixel of square a1 (read-only). Despite the name, if the board is flipped then it&#39;s square h8.
Definition: CwChessboard.h:114
void cw_chessboard_set_active_turn_indicator(CwChessboard* chessboard, gboolean white)
void cw_chessboard_draw_pawn(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
gint cw_chessboard_add_floating_piece(CwChessboard* chessboard, CwChessboardCode code, gdouble x, gdouble y, gboolean pointer_device)
void cw_chessboard_set_draw_turn_indicators(CwChessboard* chessboard, gboolean draw)
void cw_chessboard_show_cursor(CwChessboard* chessboard)
gboolean cw_chessboard_get_flip_board(CwChessboard* chessboard)
void cw_chessboard_set_light_square_color(CwChessboard* chessboard, GdkColor const* color)
gboolean cw_chessboard_default_draw_hud_square(CwChessboard* chessboard, cairo_t* cr, gint col, gint row, gint sside, guint hud)
void cw_chessboard_set_marker_thickness(CwChessboard* chessboard, gdouble thickness)
void cw_chessboard_set_background_colors(CwChessboard* chessboard, CwChessboardColorHandle const* handles)
void cw_chessboard_set_dark_square_color(CwChessboard* chessboard, GdkColor const* color)
void cw_chessboard_set_marker_color(CwChessboard* chessboard, gint col, gint row, CwChessboardColorHandle mahandle)
void cw_chessboard_get_border_color(CwChessboard* chessboard, GdkColor* color)
void cw_chessboard_draw_knight(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
void cw_chessboard_get_black_fill_color(CwChessboard* chessboard, GdkColor* color)
CwChessboardColorHandle cw_chessboard_allocate_color_handle_rgb(CwChessboard* chessboard, gdouble red, gdouble green, gdouble blue)
void cw_chessboard_set_square(CwChessboard* chessboard, gint col, gint row, CwChessboardCode code)
void cw_chessboard_set_cursor_thickness(CwChessboard* chessboard, gdouble thickness)
gboolean cw_chessboard_get_draw_turn_indicators(CwChessboard* chessboard)
This file contains the definitions of the CwChessboardCode constants.
gint const top_left_a1_x
The x coordinate of the top-left pixel of square a1 (read-only). Despite the name, if the board is flipped then it&#39;s square h8.
Definition: CwChessboard.h:112
CwChessboardCode cw_chessboard_get_square(CwChessboard* chessboard, gint col, gint row)
void cw_chessboard_draw_king(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
void cw_chessboard_get_white_line_color(CwChessboard* chessboard, GdkColor* color)
gboolean const flip_board
TRUE if the board is flipped (read-only).
Definition: CwChessboard.h:116
void cw_chessboard_get_light_square_color(CwChessboard* chessboard, GdkColor* color)
CwChessboardColorHandle cw_chessboard_get_marker_color(CwChessboard* chessboard, gint col, gint row)
CWCHESSBOARD_INLINE CwChessboardColorHandle cw_chessboard_allocate_color_handle(CwChessboard* chessboard, GdkColor const* color)
void cw_chessboard_set_white_fill_color(CwChessboard* chessboard, GdkColor const* color)
void cw_chessboard_free_color_handle(CwChessboard* chessboard, CwChessboardColorHandle handle)
gdouble cw_chessboard_get_marker_thickness(CwChessboard* chessboard)
gboolean cw_chessboard_get_draw_border(CwChessboard* chessboard)
void cw_chessboard_hide_cursor(CwChessboard* chessboard)

Copyright © 2006 - 2010 Carlo Wood.  All rights reserved.