00001 // cwchessboard -- A GTK+ chessboard widget 00002 // 00003 // Copyright (C) 2006, 2008 Carlo Wood 00004 // 00005 // Carlo Wood, Run on IRC <carlo@alinoe.com> 00006 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt 00007 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 00008 // 00009 // This program is free software; you can redistribute it and/or 00010 // modify it under the terms of the GNU General Public License 00011 // as published by the Free Software Foundation; either version 2 00012 // of the License, or (at your option) any later version. 00013 // 00014 // This program is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with this program; if not, write to the Free Software 00021 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00022 00023 //! @file CwChessboard.h 00024 //! @brief This file contains the declaration of the GTK+ widget %CwChessboard. 00025 //! @image html arrowsandmarkers.png 00026 00027 #ifndef CWCHESSBOARD_H 00028 #define CWCHESSBOARD_H 00029 00030 #include <math.h> 00031 #include <glib.h> 00032 #include <gtk/gtkdrawingarea.h> 00033 00034 #ifdef __cplusplus 00035 #define CWCHESSBOARD_INLINE inline 00036 #define CWCHESSBOARD_DEFINE_INLINE 1 00037 #else 00038 #define CWCHESSBOARD_INLINE 00039 #ifndef CWCHESSBOARD_DEFINE_INLINE 00040 #define CWCHESSBOARD_DEFINE_INLINE 0 00041 #endif 00042 #endif 00043 00044 G_BEGIN_DECLS 00045 00046 #ifdef __cplusplus 00047 #include <stdint.h> 00048 typedef uint16_t CwChessboardCode; 00049 #else 00050 #include "CwChessboardCodes.h" 00051 #endif 00052 00053 GType cw_chessboard_get_type(void) G_GNUC_CONST; 00054 00055 #define CW_TYPE_CHESSBOARD (cw_chessboard_get_type()) 00056 #define CW_CHESSBOARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CW_TYPE_CHESSBOARD, CwChessboard)) 00057 #define CW_CHESSBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CW_TYPE_CHESSBOARD, CwChessboardClass)) 00058 #define CW_IS_CHESSBOARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CW_TYPE_CHESSBOARD)) 00059 #define CW_IS_CHESSBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CW_TYPE_CHESSBOARD)) 00060 #define CW_CHESSBOARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CW_TYPE_CHESSBOARD, CwChessboardClass)) 00061 00062 typedef struct _CwChessboard CwChessboard; 00063 typedef struct _CwChessboardClass CwChessboardClass; 00064 typedef struct _CwChessboardPrivate CwChessboardPrivate; 00065 00066 /** @typedef CwChessboardColorHandle 00067 * @brief A color handle used for background markers. 00068 * 00069 * The five least significant bits determine the color 00070 * from a user defined color palet, used by the background squares 00071 * and markers. A value of zero meaning the default background value 00072 * for that square, or no marker - respectively. 00073 * 00074 * @sa cw_chessboard_allocate_color_handle_rgb, cw_chessboard_allocate_color_handle, cw_chessboard_free_color_handle, 00075 * cw_chessboard_set_background_color, cw_chessboard_get_background_color, 00076 * cw_chessboard_set_background_colors, cw_chessboard_get_background_colors, 00077 * cw_chessboard_set_marker_color, cw_chessboard_get_marker_color 00078 * / 00079 typedef unsigned char CwChessboardColorHandle; 00080 00081 /** @name Creation* / 00082 //@{ 00083 00084 /** 00085 * Create a new chessboard widget. 00086 * 00087 * @returns Newly created CwChessboard. 00088 * / 00089 GtkWidget* cw_chessboard_new(void); 00090 00091 //@} Creation 00092 00093 #ifdef DOXYGEN 00094 /** @struct CwChessboard 00095 * @brief A GTK+ chessboard widget. 00096 * 00097 * This is a GTK+ widget. For a gtkmm widget, see cwmm::ChessboardWidget. 00098 * 00099 * @sa cw_chessboard_new 00100 * / 00101 struct CwChessboard 00102 #else 00103 struct _CwChessboard 00104 #endif 00105 { 00106 GtkDrawingArea parent; 00107 CwChessboardPrivate* priv; 00108 00109 //! Square side in pixels (read only). 00110 gint const sside; 00111 //! 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. 00112 gint const top_left_a1_x; 00113 //! 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. 00114 gint const top_left_a1_y; 00115 //! TRUE if the board is flipped (read-only). 00116 gboolean const flip_board; 00117 00118 void* gtkmm_widget; // This is for use by the gtkmm class ChessboardWidget, so don't use it. 00119 }; 00120 00121 #ifdef DOXYGEN 00122 /** @struct CwChessboardClass 00123 * @brief The Class structure of %CwChessboard 00124 * / 00125 struct CwChessboardClass 00126 #else 00127 struct _CwChessboardClass 00128 #endif 00129 { 00130 GtkDrawingAreaClass parent_class; 00131 00132 /** @name Virtual functions of CwChessboard* / 00133 //@{ 00134 00135 /** 00136 * Calculate the border width of the chessboard as function of the side of a square, in pixels. 00137 * 00138 * This function must use the parameter \a sside being passed and <em>not</em> 00139 * the current sside of the passed \a chessboard (which can still be undefined even). 00140 * The main reason for this is that sside recursively depends on the result of 00141 * this function; it is called multiple times until sside stops changing and 00142 * only then the real sside is set to it's final value. 00143 * 00144 * @param chessboard A #CwChessboard. 00145 * @param sside The size of one side of a square. 00146 * 00147 * @returns The width of the border in pixels. 00148 * 00149 * Default value: #cw_chessboard_default_calc_board_border_width 00150 * / 00151 gint (*calc_board_border_width)(CwChessboard const* chessboard, gint sside); 00152 00153 /** 00154 * Draw the border around the chessboard. 00155 * This function is called when the border is first drawn, 00156 * and every time the chessboard is resized. 00157 * 00158 * The width of the drawn border should be the value returned by #calc_board_border_width. 00159 * 00160 * @param chessboard A #CwChessboard. 00161 * 00162 * Default value: #cw_chessboard_default_draw_border 00163 * 00164 * @sa cw_chessboard_set_draw_border 00165 * / 00166 void (*draw_border)(CwChessboard* chessboard); 00167 00168 /** 00169 * Draw the indicator that indicates whose turn it is. 00170 * This function is called every time the border is redrawn, 00171 * as well as every time #cw_chessboard_set_draw_turn_indicators 00172 * is called. 00173 * 00174 * @param chessboard A #CwChessboard. 00175 * @param white True if the indicator of the white color has to be drawn. 00176 * @param on True if the indictor is on, false if it is off. 00177 * 00178 * Default value: #cw_chessboard_default_draw_turn_indicator 00179 * 00180 * @sa cw_chessboard_set_draw_border, cw_chessboard_set_draw_turn_indicators 00181 * / 00182 void (*draw_turn_indicator)(CwChessboard* chessboard, gboolean white, gboolean on); 00183 00184 /** 00185 * An array with function pointers for drawing chess pieces. 00186 * 00187 * The functions draw one of the six chess pieces, both white and black. 00188 * The index of the array refers to the piece being drawn: 00189 * pawn = 0, rook = 1, bishop = 2, knight = 3, queen = 4, king = 5. 00190 * 00191 * The default values are given below. 00192 * They can be overridden by assigning other values to this array. 00193 * 00194 * \sa cw_chessboard_draw_pawn, 00195 * cw_chessboard_draw_rook, 00196 * cw_chessboard_draw_bishop, 00197 * cw_chessboard_draw_knight, 00198 * cw_chessboard_draw_queen, 00199 * cw_chessboard_draw_king 00200 * / 00201 void (*draw_piece[6])(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white); 00202 00203 /** 00204 * Draw the HUD layer. This is a layer in between the background 00205 * (existing of the 64 squares with a single color) and the layer 00206 * with the pieces. It can be used to add some texture to the 00207 * background. 00208 * 00209 * If the HUD layer is active, then this function is called 00210 * whenever the widget is resized. 00211 * 00212 * @param chessboard A #CwChessboard. 00213 * @param cr A cairo drawing context. 00214 * @param sside The size of one side of a square, in pixels. 00215 * @param hud The HUD index number, see the detailed documentation on the \ref index "main page" for more info. 00216 * 00217 * Default value: #cw_chessboard_default_draw_hud_layer 00218 * 00219 * @sa cw_chessboard_enable_hud_layer, 00220 * cw_chessboard_disable_hud_layer, 00221 * cw_chessboard_default_draw_hud_layer 00222 * / 00223 void (*draw_hud_layer)(CwChessboard* chessboard, cairo_t* cr, gint sside, guint hud); 00224 00225 /** 00226 * Draw a single HUD square at \a col, \a row. 00227 * This function is called by cw_chessboard_default_draw_hud_layer 00228 * for each square. You can use it if you don't override draw_hud_layer. 00229 * 00230 * @param chessboard A #CwChessboard. 00231 * @param cr A cairo drawing context. 00232 * @param col The column of the square. 00233 * @param row The row of the square. 00234 * @param sside The size of one side of the square, in pixels. 00235 * @param hud The HUD index number, see the detailed documentation of \ref index "main page" for more info. 00236 * 00237 * @returns TRUE if anything was drawn at all, FALSE if the HUD square is fully transparent. 00238 * / 00239 gboolean (*draw_hud_square)(CwChessboard* chessboard, cairo_t* cr, gint col, gint row, gint sside, guint hud); 00240 00241 /** 00242 * Notify the user that the mouse pointer left the chessboard. 00243 * 00244 * If non-NULL, this function is called every time the mouse pointer 00245 * leaves the chessboard. 00246 * 00247 * Default value: NULL. 00248 * 00249 * @param chessboard A #CwChessboard. 00250 * @param prev_col The column of the last square. 00251 * @param prev_row The row of the last square. 00252 * / 00253 void (*cursor_left_chessboard)(CwChessboard* chessboard, gint prev_col, gint prev_row); 00254 00255 /** 00256 * Notify the user that the mouse pointer entered a different square. 00257 * 00258 * If non-NULL, this function is called every time the mouse pointer enters 00259 * a new square, whether from outside the chessboard or from another square. 00260 * 00261 * Default value: NULL. 00262 * 00263 * @param chessboard A #CwChessboard. 00264 * @param prev_col The column of the last square, or -1 if we entered from outside the chessboard. 00265 * @param prev_row The row of the last square, or -1 if we entered from outside the chessboard. 00266 * @param col The column of the entered square. 00267 * @param row The row of the entered square. 00268 * / 00269 void (*cursor_entered_square)(CwChessboard* chessboard, gint prev_col, gint prev_row, gint col, gint row); 00270 00271 //@} 00272 00273 }; 00274 00275 /** 00276 * Convert a (\a col, \a row) pair to the top-left coordinates of the corresponding square, 00277 * relative to the top-left of the widget. 00278 * 00279 * @param chessboard A #CwChessboard. 00280 * @param col A column, in the range [0, 7]. 00281 * @param row A row, in the range [0, 7]. 00282 * @param x A pointer to where the x-coordinate of the result will be written to. 00283 * @param y A pointer to where the y-coordinate of the result will be written to. 00284 * / 00285 CWCHESSBOARD_INLINE 00286 void cw_chessboard_colrow2xy(CwChessboard* chessboard, gint col, gint row, gint* x, gint* y) 00287 #if CWCHESSBOARD_DEFINE_INLINE 00288 { 00289 * x = chessboard->top_left_a1_x + (chessboard->flip_board ? 7 - col : col) * chessboard->sside; 00290 * y = chessboard->top_left_a1_y - (chessboard->flip_board ? 7 - row : row) * chessboard->sside; 00291 } 00292 #else 00293 ; 00294 #endif 00295 00296 /** 00297 * Convert an x-coordinate to the column number that it matches. 00298 * If the x coordinate falls outside the board, then the returned value 00299 * will be outside the range [0, 7]. 00300 * 00301 * @param chessboard A #CwChessboard. 00302 * @param x An x coordinate, relative to the left-side of the widget. 00303 * 00304 * @returns A column number. 00305 * / 00306 CWCHESSBOARD_INLINE 00307 gint cw_chessboard_x2col(CwChessboard* chessboard, gdouble x) 00308 #if CWCHESSBOARD_DEFINE_INLINE 00309 { 00310 gint xcol = (gint)floor((x - chessboard->top_left_a1_x) / chessboard->sside); 00311 return (chessboard->flip_board ? 7 - xcol : xcol); 00312 } 00313 #else 00314 ; 00315 #endif 00316 00317 /** 00318 * Convert a y-coordinate to the row number that it matches. 00319 * If the y coordinate falls outside the board, then the returned value 00320 * will be outside the range [0, 7]. 00321 * 00322 * @param chessboard A #CwChessboard. 00323 * @param y A y coordinate, relative to the top-side of the widget. 00324 * 00325 * @returns A row number. 00326 * / 00327 CWCHESSBOARD_INLINE 00328 gint cw_chessboard_y2row(CwChessboard* chessboard, gdouble y) 00329 #if CWCHESSBOARD_DEFINE_INLINE 00330 { 00331 gint yrow = (gint)floor((chessboard->top_left_a1_y + chessboard->sside - 1 - y) / chessboard->sside); 00332 return (chessboard->flip_board ? 7 - yrow : yrow); 00333 } 00334 #else 00335 ; 00336 #endif 00337 00338 /** @name Chess Position* / 00339 //@{ 00340 00341 /** 00342 * Change or remove the piece on the square (\a col, \a row), 00343 * by replacing the contents of the square with \a code. 00344 * This does not change any other attribute of the square, 00345 * like it's background color or marker. 00346 * 00347 * @param chessboard A #CwChessboard. 00348 * @param col A column [0..7] 00349 * @param row A row [0..7] 00350 * @param code A #CwChessboardCode. 00351 * / 00352 void cw_chessboard_set_square(CwChessboard* chessboard, gint col, gint row, CwChessboardCode code); 00353 00354 /** 00355 * Get the chess piece code for the square at (\a col, \a row). 00356 * / 00357 CwChessboardCode cw_chessboard_get_square(CwChessboard* chessboard, gint col, gint row); 00358 00359 //@} Chess Position 00360 00361 /** @name Border* / 00362 //@{ 00363 00364 /** 00365 * Set the boolean which determines whether or not the chessboard widget 00366 * draws a border around the chessboard. Default: TRUE (draw border). 00367 * 00368 * @param chessboard A #CwChessboard. 00369 * @param draw Boolean, determining if the border should be drawn. 00370 * 00371 * @sa CwChessboardClass::calc_board_border_width, CwChessboardClass::draw_border 00372 * / 00373 void cw_chessboard_set_draw_border(CwChessboard* chessboard, gboolean draw); 00374 00375 /** 00376 * Set the boolean which determines whether or not to draw turn indicators. 00377 * Indicators will only be drawn if also the border is drawn. 00378 * Default: TRUE (draw indicators). 00379 * 00380 * @param chessboard A #CwChessboard. 00381 * @param draw Boolean, determining if the indicators should be drawn. 00382 * 00383 * @sa cw_chessboard_set_draw_border, CwChessboardClass::draw_turn_indicator 00384 * / 00385 void cw_chessboard_set_draw_turn_indicators(CwChessboard* chessboard, gboolean draw); 00386 00387 /** 00388 * Set the boolean that detemines which turn indicator is active (blacks or whites). 00389 * If drawing turn indicators is enabled and the color is changed then the old 00390 * indicator is erased. If the turn indicators are disabled, nothing happens. 00391 * 00392 * @param chessboard A #CwChessboard. 00393 * @param white TRUE if the white turn indicator should be on (and blacks off). 00394 * 00395 * @sa cw_chessboard_set_draw_turn_indicators 00396 * / 00397 void cw_chessboard_set_active_turn_indicator(CwChessboard* chessboard, gboolean white); 00398 00399 /** 00400 * Set the boolean which determines whether white is playing bottom up or top down. 00401 * Default: FALSE (white plays upwards). 00402 * 00403 * @param chessboard A #CwChessboard. 00404 * @param flip Boolean, determining if white plays upwards or not. 00405 * / 00406 void cw_chessboard_set_flip_board(CwChessboard* chessboard, gboolean flip); 00407 00408 /** 00409 * Get the boolean that determines whether or not the chessboard widget draws a border around the chessboard. 00410 * 00411 * @param chessboard A #CwChessboard. 00412 * 00413 * @returns <code>TRUE</code> if the border is being drawn. 00414 * 00415 * @sa cw_chessboard_set_draw_border 00416 * / 00417 gboolean cw_chessboard_get_draw_border(CwChessboard* chessboard); 00418 00419 /** 00420 * Get the boolean that determines whether or not turn indicators are being drawn. 00421 * 00422 * @param chessboard A #CwChessboard. 00423 * 00424 * @returns <code>TRUE</code> if turn indicators are being drawn. 00425 * 00426 * @sa cw_chessboard_set_draw_turn_indicators 00427 * / 00428 gboolean cw_chessboard_get_draw_turn_indicators(CwChessboard* chessboard); 00429 00430 /** 00431 * Get the boolean that detemines which turn indicator is active (blacks or whites). 00432 * 00433 * @param chessboard A #CwChessboard. 00434 * 00435 * @returns <code>TRUE</code> if whites turn indicator is active (independent on whether or not it is being drawn). 00436 * 00437 * @sa cw_chessboard_set_active_turn_indicator 00438 * / 00439 gboolean cw_chessboard_get_active_turn_indicator(CwChessboard* chessboard); 00440 00441 /** 00442 * Get the boolean which determines whether white is playing bottom up or top down. 00443 * 00444 * @param chessboard A #CwChessboard. 00445 * 00446 * @returns <code>FALSE</code> if white plays upwards and <code>TRUE</code> if white plays downwards. 00447 * 00448 * @sa cw_chessboard_set_flip_board 00449 * / 00450 gboolean cw_chessboard_get_flip_board(CwChessboard* chessboard); 00451 00452 /** 00453 * This is the default value of CwChessboardClass::calc_board_border_width. 00454 * The formula used by this default function is MAX(8.0, round(1.0 + (sside - 12) / 25.0) + sside / 3.0). 00455 * 00456 * @param chessboard A #CwChessboard. 00457 * @param sside The size of one side of a square in pixels. 00458 * 00459 * @returns The border width in pixels. 00460 * 00461 * @sa CwChessboardClass::calc_board_border_width 00462 * / 00463 gint cw_chessboard_default_calc_board_border_width(CwChessboard const* chessboard, gint sside); 00464 00465 //@} The Border 00466 00467 /** @name Colors* / 00468 //@{ 00469 00470 /** 00471 * Set the background color of the dark squares (a1, c1 etc). 00472 * Default: light green. 00473 * 00474 * @param chessboard A #CwChessboard. 00475 * @param color The new color of the dark squares. 00476 * / 00477 void cw_chessboard_set_dark_square_color(CwChessboard* chessboard, GdkColor const* color); 00478 00479 /** 00480 * Set the background color of the light squares (b1, d1 etc). 00481 * Default: yellow/white. 00482 * 00483 * @param chessboard A #CwChessboard. 00484 * @param color The new color of the light squares. 00485 * / 00486 void cw_chessboard_set_light_square_color(CwChessboard* chessboard, GdkColor const* color); 00487 00488 /** 00489 * Set the color of the border around the chessboard. 00490 * 00491 * @param chessboard A #CwChessboard. 00492 * @param color The new color of the border. 00493 * 00494 * @sa cw_chessboard_get_border_color, cw_chessboard_set_draw_border 00495 * / 00496 void cw_chessboard_set_border_color(CwChessboard* chessboard, GdkColor const* color); 00497 00498 /** 00499 * Set the fill color of the white chess pieces. 00500 * Default: white 00501 * 00502 * @param chessboard A #CwChessboard. 00503 * @param color The new fill color of the white pieces. 00504 * / 00505 void cw_chessboard_set_white_fill_color(CwChessboard* chessboard, GdkColor const* color); 00506 00507 /** 00508 * Set the line color of the white chess pieces. 00509 * Default: black 00510 * 00511 * @param chessboard A #CwChessboard. 00512 * @param color The new line color of the white pieces. 00513 * / 00514 void cw_chessboard_set_white_line_color(CwChessboard* chessboard, GdkColor const* color); 00515 00516 /** 00517 * Set the fill color of the black chess pieces. 00518 * Default: black 00519 * 00520 * @param chessboard A #CwChessboard. 00521 * @param color The new fill color of the black pieces. 00522 * / 00523 void cw_chessboard_set_black_fill_color(CwChessboard* chessboard, GdkColor const* color); 00524 00525 /** 00526 * Set the line color of the black chess pieces. 00527 * Default: white 00528 * 00529 * @param chessboard A #CwChessboard. 00530 * @param color The new line color of the black pieces. 00531 * / 00532 void cw_chessboard_set_black_line_color(CwChessboard* chessboard, GdkColor const* color); 00533 00534 /** 00535 * Retrieve the current background color of the dark squares. 00536 * 00537 * @param chessboard A #CwChessboard. 00538 * @param color Pointer to the output variable. 00539 * 00540 * @sa cw_chessboard_set_dark_square_color 00541 * / 00542 void cw_chessboard_get_dark_square_color(CwChessboard* chessboard, GdkColor* color); 00543 00544 /** 00545 * Retrieve the current background color of the light squares. 00546 * 00547 * @param chessboard A #CwChessboard. 00548 * @param color Pointer to the output variable. 00549 * 00550 * @sa cw_chessboard_set_light_square_color 00551 * / 00552 void cw_chessboard_get_light_square_color(CwChessboard* chessboard, GdkColor* color); 00553 00554 /** 00555 * Retrieve the current color of the border around the chessboard. 00556 * 00557 * @param chessboard A #CwChessboard. 00558 * @param color Pointer to the output variable. 00559 * 00560 * @sa cw_chessboard_set_border_color 00561 * / 00562 void cw_chessboard_get_border_color(CwChessboard* chessboard, GdkColor* color); 00563 00564 /** 00565 * Retrieve the current fill color of the white chess pieces. 00566 * 00567 * @param chessboard A #CwChessboard. 00568 * @param color Pointer to the output variable. 00569 * 00570 * @sa cw_chessboard_set_white_fill_color 00571 * / 00572 void cw_chessboard_get_white_fill_color(CwChessboard* chessboard, GdkColor* color); 00573 00574 /** 00575 * Retrieve the current line color of the white chess pieces. 00576 * 00577 * @param chessboard A #CwChessboard. 00578 * @param color Pointer to the output variable. 00579 * 00580 * @sa cw_chessboard_set_white_line_color 00581 * / 00582 void cw_chessboard_get_white_line_color(CwChessboard* chessboard, GdkColor* color); 00583 00584 /** 00585 * Retrieve the current fill color of the black chess pieces. 00586 * 00587 * @param chessboard A #CwChessboard. 00588 * @param color Pointer to the output variable. 00589 * 00590 * @sa cw_chessboard_set_black_fill_color 00591 * / 00592 void cw_chessboard_get_black_fill_color(CwChessboard* chessboard, GdkColor* color); 00593 00594 /** 00595 * Retrieve the current line color of the black chess pieces. 00596 * 00597 * @param chessboard A #CwChessboard. 00598 * @param color Pointer to the output variable. 00599 * 00600 * @sa cw_chessboard_set_black_line_color 00601 * / 00602 void cw_chessboard_get_black_line_color(CwChessboard* chessboard, GdkColor* color); 00603 00604 /** 00605 * Allocate a new CwChessboardColorHandle. 00606 * Simultaneous, there can be at most 31 different colors. 00607 * It is the responsibility of the user to free the colors if they are no longer used. 00608 * 00609 * @param chessboard A #CwChessboard. 00610 * @param red The red component of the color in the range [0...1]. 00611 * @param green The green component of the color in the range [0...1]. 00612 * @param blue The blue component of the color in the range [0...1]. 00613 * 00614 * @returns A color handle that can be used with #cw_chessboard_set_background_color and #cw_chessboard_set_marker_color. 00615 * 00616 * @sa cw_chessboard_allocate_color_handle, cw_chessboard_free_color_handle 00617 * / 00618 CwChessboardColorHandle cw_chessboard_allocate_color_handle_rgb(CwChessboard* chessboard, 00619 gdouble red, gdouble green, gdouble blue); 00620 00621 /** 00622 * Allocate a new CwChessboardColorHandle. 00623 * From more information, see #cw_chessboard_allocate_color_handle_rgb. 00624 * 00625 * @param chessboard A #CwChessboard. 00626 * @param color The color to allocate. 00627 * 00628 * @returns A color handle that can be used with #cw_chessboard_set_background_color and #cw_chessboard_set_marker_color. 00629 * 00630 * @sa cw_chessboard_free_color_handle 00631 * / 00632 CWCHESSBOARD_INLINE 00633 CwChessboardColorHandle cw_chessboard_allocate_color_handle(CwChessboard* chessboard, GdkColor const* color) 00634 #if CWCHESSBOARD_DEFINE_INLINE 00635 { 00636 return cw_chessboard_allocate_color_handle_rgb(chessboard, color->red / 65535.0, 00637 color->green / 65535.0, color->blue / 65535.0); 00638 } 00639 #else 00640 ; 00641 #endif 00642 00643 /** 00644 * Free up the color handle \a handle, so it can be reused. 00645 * 00646 * @param chessboard A #CwChessboard. 00647 * @param handle A color handle as returned by cw_chessboard_allocate_color_handle_rgb or cw_chessboard_allocate_color_handle. 00648 * 00649 * @sa cw_chessboard_allocate_color_handle_rgb, cw_chessboard_allocate_color_handle 00650 * / 00651 void cw_chessboard_free_color_handle(CwChessboard* chessboard, CwChessboardColorHandle handle); 00652 00653 /** 00654 * Set the background color of the square at \a col, \a row. 00655 * 00656 * @param chessboard A #CwChessboard. 00657 * @param col The column of the square. 00658 * @param row The row of the square. 00659 * @param handle A color handle as returned by #cw_chessboard_allocate_color_handle_rgb or 00660 * #cw_chessboard_allocate_color_handle. A handle with a value of 0 means the 00661 * default background color. 00662 * / 00663 void cw_chessboard_set_background_color(CwChessboard* chessboard, gint col, gint row, CwChessboardColorHandle handle); 00664 00665 /** 00666 * Convenience function. 00667 * 00668 * @param chessboard A #CwChessboard. 00669 * @param col The column of the square. 00670 * @param row The row of the square. 00671 * 00672 * @returns The handle that was passed to #cw_chessboard_set_background_color 00673 * for this square, or 0 if the square is not associated with a color handle. 00674 * / 00675 CwChessboardColorHandle cw_chessboard_get_background_color(CwChessboard* chessboard, gint col, gint row); 00676 00677 /** 00678 * Set new background colors of any number of squares. 00679 * 00680 * @param chessboard A #CwChessboard. 00681 * @param handles Array of 64 CwChessboardColorHandles. 00682 * A handle with a value of 0 means the default background color. 00683 * / 00684 void cw_chessboard_set_background_colors(CwChessboard* chessboard, CwChessboardColorHandle const* handles); 00685 00686 /** 00687 * Fill the array \a handles with the current color handles. 00688 * 00689 * @param chessboard A #CwChessboard. 00690 * @param handles The output array. Should be an array of 64 CwChessboardColorHandles. 00691 * / 00692 void cw_chessboard_get_background_colors(CwChessboard* chessboard, CwChessboardColorHandle* handles); 00693 00694 //@} Colors 00695 00696 /** @name Floating Pieces* / 00697 //@{ 00698 00699 /** 00700 * This function displays a chess piece with code \a code at widget coordinates (\a x, \a y). 00701 * Half the side of a square will be subtracted from the coordinates passed, and 00702 * the result truncated, in order to determine where to draw the top-left corner 00703 * of the piece. The result is that (\a x, \a y) is more or less the center of the piece. 00704 * 00705 * Setting \a pointer_device will cause gdk_window_get_pointer to be called 00706 * after the next redraw has finished. This is needed to receive the next motion 00707 * notify event with GDK_POINTER_MOTION_HINT_MASK being used. 00708 * 00709 * There may only be one floating piece related the pointer device at a time. 00710 * If there is already another floating piece related to the pointer device 00711 * then the value of \a pointer_device is ignored. 00712 * 00713 * @param chessboard A #CwChessboard. 00714 * @param code The code of the chess piece to be drawn. 00715 * @param x The center x-coordinate of the piece. 00716 * @param y The center y-coordinate of the piece. 00717 * @param pointer_device Whether this piece is under the pointer device or not. 00718 * 00719 * @returns A handle that can be passed to each of the functions below. 00720 * 00721 * @sa cw_chessboard_get_floating_piece, 00722 * cw_chessboard_remove_floating_piece, 00723 * cw_chessboard_move_floating_piece 00724 * / 00725 gint cw_chessboard_add_floating_piece(CwChessboard* chessboard, 00726 CwChessboardCode code, gdouble x, gdouble y, gboolean pointer_device); 00727 00728 /** 00729 * Move a floating piece with handle \a handle to the new widget 00730 * coordinates at (\a x, \a y). \a handle must be a handle as 00731 * returned by #cw_chessboard_add_floating_piece. 00732 * 00733 * @param chessboard A #CwChessboard. 00734 * @param handle The floating piece handle. 00735 * @param x The new x coordinate. 00736 * @param y The new y coordinate. 00737 * 00738 * @sa cw_chessboard_add_floating_piece 00739 * / 00740 void cw_chessboard_move_floating_piece(CwChessboard* chessboard, gint handle, gdouble x, gdouble y); 00741 00742 /** 00743 * Delete the floating piece with handle \a handle. 00744 * \a handle must be a handle as returned by #cw_chessboard_add_floating_piece. 00745 * 00746 * @param chessboard A #CwChessboard. 00747 * @param handle The floating piece handle. 00748 * / 00749 void cw_chessboard_remove_floating_piece(CwChessboard* chessboard, gint handle); 00750 00751 /** 00752 * Get the CwChessboardCode of the floating piece represented by \a handle. 00753 * \a handle must be a handle as returned by #cw_chessboard_add_floating_piece. 00754 * 00755 * @param chessboard A #CwChessboard. 00756 * @param handle The floating piece handle. 00757 * / 00758 CwChessboardCode cw_chessboard_get_floating_piece(CwChessboard* chessboard, gint handle); 00759 00760 //@} Floating Pieces 00761 00762 /** @name Default Drawing Functions* / 00763 //@{ 00764 00765 /** 00766 * This is the default function used by CwChessboard to draw pawns. 00767 * 00768 * If \a white is set, a white pawn will be drawn. Otherwise a black pawn. 00769 * 00770 * <code>cw_chessboard_draw_pawn</code> is the default function called 00771 * via a call to CwChessboardClass::draw_piece. 00772 * It is called every time the chessboard is resized. 00773 * 00774 * The function uses vector graphics (by doing direct calls to cairo), 00775 * and is therefore capable of drawing the piece in any arbitrary size 00776 * and uses anti-aliasing. 00777 * 00778 * @image html pawn.png 00779 * 00780 * @param chessboard A #CwChessboard. 00781 * @param cr The cairo drawing context. 00782 * @param x The (widget) x-coordinate of the center of the piece. 00783 * @param y The (widget) y-coordinate of the center of the piece. 00784 * @param sside The assumed side of a square, in pixels. 00785 * <code>chessboard->sside</code> is ignored, so that 00786 * this function can be used to draw pieces elsewhere with a different 00787 * size than what is used on the chessboard. 00788 * @param white A boolean that determines if a black or white piece is drawn. 00789 * / 00790 void cw_chessboard_draw_pawn(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white); 00791 00792 /** 00793 * This is the default function used by CwChessboard to draw a rook. 00794 * 00795 * @image html rook.png 00796 * 00797 * See #cw_chessboard_draw_pawn for more details. 00798 * / 00799 void cw_chessboard_draw_rook(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white); 00800 00801 /** 00802 * This is the default function used by CwChessboard to draw a knight. 00803 * 00804 * @image html knight.png 00805 * 00806 * See #cw_chessboard_draw_pawn for more details. 00807 * / 00808 void cw_chessboard_draw_knight(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white); 00809 00810 /** 00811 * This is the default function used by CwChessboard to draw a bishop. 00812 * 00813 * @image html bishop.png 00814 * 00815 * See #cw_chessboard_draw_pawn for more details. 00816 * / 00817 void cw_chessboard_draw_bishop(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white); 00818 00819 /** 00820 * This is the default function used by CwChessboard to draw a queen. 00821 * 00822 * @image html queen.png 00823 * 00824 * See #cw_chessboard_draw_pawn for more details. 00825 * / 00826 void cw_chessboard_draw_queen(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white); 00827 00828 /** 00829 * This is the default function used by CwChessboard to draw a king. 00830 * 00831 * @image html king.png 00832 * 00833 * See #cw_chessboard_draw_pawn for more details. 00834 * / 00835 void cw_chessboard_draw_king(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white); 00836 00837 /** 00838 * The default CwChessboardClass::draw_hud_layer function. 00839 * You can restore the default behaviour with: 00840 * \code 00841 * CW_CHESSBOARD_GET_CLASS(chessboard)->draw_hud_layer = cw_chessboard_default_draw_hud_layer; 00842 * \endcode 00843 * 00844 * @param chessboard A #CwChessboard. 00845 * @param cr The cairo drawing context. 00846 * @param sside The side of one square in pixels. 00847 * @param hud The HUD layer (0 or 1). 00848 * 00849 * This function calls CwChessboardClass::draw_hud_square for every square. 00850 * / 00851 void cw_chessboard_default_draw_hud_layer(CwChessboard* chessboard, cairo_t* cr, gint sside, guint hud); 00852 00853 /** 00854 * The default CwChessboardClass::draw_hud_square function. 00855 * This function is only used by cw_chessboard_default_draw_hud_layer. 00856 * You can restore the default behaviour of cw_chessboard_default_draw_hud_layer with: 00857 * \code 00858 * CW_CHESSBOARD_GET_CLASS(chessboard)->draw_hud_square = cw_chessboard_default_draw_hud_square; 00859 * \endcode 00860 * 00861 * This function hatches the dark squares with fine, diagonal lines. 00862 * 00863 * @param chessboard A #CwChessboard. 00864 * @param cr The cairo drawing context. 00865 * @param col The column of the square. 00866 * @param row The row of the square. 00867 * @param sside The side of one square in pixels. 00868 * @param hud The HUD layer (0 or 1). 00869 * 00870 * @returns <code>TRUE</code> if anything was drawn. <code>FALSE</code> otherwise. 00871 * / 00872 gboolean cw_chessboard_default_draw_hud_square(CwChessboard* chessboard, 00873 cairo_t* cr, gint col, gint row, gint sside, guint hud); 00874 00875 /** 00876 * This is the default value of CwChessboardClass::draw_border. 00877 * 00878 * @param chessboard A #CwChessboard. 00879 * / 00880 void cw_chessboard_default_draw_border(CwChessboard* chessboard); 00881 00882 /** 00883 * This is the default value of CwChessboardClass::draw_turn_indicator. 00884 * 00885 * @param chessboard A #CwChessboard. 00886 * @param white TRUE if it's whites indicator. 00887 * @param on TRUE if the indicator has to be drawn, FALSE if the indicator has to be removed. 00888 * / 00889 void cw_chessboard_default_draw_turn_indicator(CwChessboard* chessboard, gboolean white, gboolean on); 00890 00891 //@} Default Virtual Functions 00892 00893 /** @name HUD Layers* / 00894 //@{ 00895 00896 /** 00897 * Active a HUD layer. 00898 * HUD 0 lays between the background and the pieces. 00899 * HUD 1 lays above the pieces. 00900 * A custom HUD layer can be created by setting CwChessboardClass::draw_hud_layer. 00901 * 00902 * @param chessboard A #CwChessboard. 00903 * @param hud The HUD layer (0 or 1). 00904 * 00905 * @sa CwChessboardClass::draw_hud_layer, cw_chessboard_disable_hud_layer 00906 * / 00907 void cw_chessboard_enable_hud_layer(CwChessboard* chessboard, guint hud); 00908 00909 /** 00910 * Disable the HUD layer again. Used resources are returned to the system. 00911 * 00912 * @param chessboard A #CwChessboard. 00913 * @param hud The HUD layer (0 or 1). 00914 * 00915 * @sa cw_chessboard_enable_hud_layer 00916 * / 00917 void cw_chessboard_disable_hud_layer(CwChessboard* chessboard, guint hud); 00918 00919 //@} // HUD Layers 00920 00921 /** @name Markers* / 00922 //@{ 00923 00924 /** 00925 * Add (or remove) a marker to the square at \a col, \a row. 00926 * 00927 * @param chessboard A #CwChessboard. 00928 * @param col The column of the square. 00929 * @param row The row of the square. 00930 * @param mahandle A color handle as returned by #cw_chessboard_allocate_color_handle_rgb or 00931 * #cw_chessboard_allocate_color_handle. A handle with a value of 0 means the 00932 * default background color. 00933 * / 00934 void cw_chessboard_set_marker_color(CwChessboard* chessboard, 00935 gint col, gint row, CwChessboardColorHandle mahandle); 00936 00937 /** 00938 * Convenience function. 00939 * 00940 * @param chessboard A #CwChessboard. 00941 * @param col The column of the square. 00942 * @param row The row of the square. 00943 * 00944 * @returns The handle that was passed to #cw_chessboard_set_marker_color 00945 * for this square, or 0 if the square doesn't have a marker. 00946 * / 00947 CwChessboardColorHandle cw_chessboard_get_marker_color(CwChessboard* chessboard, gint col, gint row); 00948 00949 /** 00950 * Set the marker thickness. This is a value between 0 and 0.5. 00951 * 00952 * @param chessboard A #CwChessboard. 00953 * @param thickness The thickness of the marker as fraction of sside. Range [0...0.5] 00954 * 00955 * @sa cw_chessboard_get_marker_thickness 00956 * / 00957 void cw_chessboard_set_marker_thickness(CwChessboard* chessboard, gdouble thickness); 00958 00959 /** 00960 * Get the current marker thickness as fraction of sside. 00961 * 00962 * @param chessboard A #CwChessboard. 00963 * 00964 * @sa cw_chessboard_set_marker_thickness 00965 * / 00966 gdouble cw_chessboard_get_marker_thickness(CwChessboard* chessboard); 00967 00968 /** 00969 * Choose whether markers should be drawn below or above HUD layer 0. 00970 * 00971 * Markers can be drawn directly below or directly above HUD layer 0. 00972 * 00973 * @param chessboard A #CwChessboard. 00974 * @param below TRUE when markers should be drawn below HUD layer 0. 00975 * / 00976 void cw_chessboard_set_marker_level(CwChessboard* chessboard, gboolean below); 00977 00978 //@} Markers 00979 00980 /** @name Cursor* / 00981 //@{ 00982 00983 /** 00984 * Show the cursor. 00985 * 00986 * This high-lights the square under the mouse by drawing a 00987 * square with a configurable thickness and color. 00988 * 00989 * @param chessboard A #CwChessboard. 00990 * 00991 * @sa cw_chessboard_set_cursor_thickness, cw_chessboard_get_cursor_thickness 00992 * / 00993 void cw_chessboard_show_cursor(CwChessboard* chessboard); 00994 00995 /** 00996 * Hide the cursor. 00997 * 00998 * @param chessboard A #CwChessboard. 00999 * 01000 * @sa cw_chessboard_show_cursor 01001 * / 01002 void cw_chessboard_hide_cursor(CwChessboard* chessboard); 01003 01004 /** 01005 * Set the cursor thickness. This is a value between 0 and 0.5. 01006 * 01007 * @param chessboard A #CwChessboard. 01008 * @param thickness The thickness of the cursor as fraction of sside. Range [0...0.5] 01009 * 01010 * @sa cw_chessboard_get_cursor_thickness 01011 * / 01012 void cw_chessboard_set_cursor_thickness(CwChessboard* chessboard, gdouble thickness); 01013 01014 /** 01015 * Get the current cursor thickness as fraction of sside. 01016 * 01017 * @param chessboard A #CwChessboard. 01018 * 01019 * @sa cw_chessboard_set_cursor_thickness 01020 * / 01021 gdouble cw_chessboard_get_cursor_thickness(CwChessboard* chessboard); 01022 01023 /** 01024 * Set the color of the cursor. 01025 * 01026 * @param chessboard A #CwChessboard. 01027 * @param color The color to be used for the cursor. 01028 * / 01029 void cw_chessboard_set_cursor_color(CwChessboard* chessboard, GdkColor const* color); 01030 01031 /** 01032 * Get the current cursor color. 01033 * 01034 * @param chessboard A #CwChessboard. 01035 * @param color Pointer to the output variable. 01036 * / 01037 void cw_chessboard_get_cursor_color(CwChessboard* chessboard, GdkColor* color); 01038 01039 //@} Cursor 01040 01041 /** @name Arrows* / 01042 //@{ 01043 01044 /** 01045 * Draw an arrow on the board. 01046 * 01047 * @param chessboard A #CwChessboard. 01048 * @param begin_col The column of the starting square. 01049 * @param begin_row The row of the starting square. 01050 * @param end_col The column of the ending square. 01051 * @param end_row The row of the ending square. 01052 * @param color The color to draw the arrow in. 01053 * 01054 * @returns A handle that can be used to remove the arrow again. 01055 * 01056 * @sa cw_chessboard_remove_arrow 01057 * / 01058 gpointer cw_chessboard_add_arrow(CwChessboard* chessboard, 01059 gint begin_col, gint begin_row, gint end_col, gint end_row, GdkColor const* color); 01060 01061 /** 01062 * Remove a previously added arrow. 01063 * 01064 * @param chessboard A #CwChessboard. 01065 * @param ptr The arrow handle as returned by #cw_chessboard_add_arrow. 01066 * / 01067 void cw_chessboard_remove_arrow(CwChessboard* chessboard, gpointer ptr); 01068 01069 //@} Arrows 01070 01071 G_END_DECLS 01072 01073 #endif // CWCHESSBOARD_H