00001 // cwchessboard -- A C++ chessboard tool set for gtkmm 00002 // 00003 //! @file ChessboardWidget.h This file contains the declaration of the gtkmm class ChessboardWidget. 00004 // 00005 // Copyright (C) 2008, by 00006 // 00007 // Carlo Wood, Run on IRC <carlo@alinoe.com> 00008 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt 00009 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 00010 // 00011 // This program is free software: you can redistribute it and/or modify 00012 // it under the terms of the GNU General Public License as published by 00013 // the Free Software Foundation, either version 2 of the License, or 00014 // (at your option) any later version. 00015 // 00016 // This program is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU General Public License 00022 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00023 00024 #ifndef CHESSBOARD_H 00025 #define CHESSBOARD_H 00026 00027 #ifndef USE_PCH 00028 #include "debug.h" 00029 #endif 00030 00031 #include <gtkmm/drawingarea.h> 00032 #include "CwChessboard.h" 00033 00034 /** @namespace cwmm 00035 * @brief A namespace for all gtkmm related objects. 00036 * / 00037 namespace cwmm { 00038 00039 /** @internal 00040 * 00041 * A helper class, needed because we must initialize CwChessboard before we can initialize Gtk::DrawingArea. 00042 * / 00043 class CwChessboardPtr { 00044 protected: 00045 CwChessboard* M_chessboard; 00046 CwChessboardPtr(void) : M_chessboard(CW_CHESSBOARD(cw_chessboard_new())) { } 00047 }; 00048 00049 /** @class ChessboardWidget 00050 * @brief A gtkmm chessboard widget. 00051 * 00052 * This is a chessboard widget for use with gtkmm. 00053 * 00054 * A detailed overview can be found on the <a href="index.html">Main Page</a>. 00055 * 00056 * @sa ChessPositionWidget 00057 * / 00058 class ChessboardWidget : public CwChessboardPtr, public Gtk::DrawingArea { 00059 public: 00060 /** @name Construction/Destruction* / 00061 //@{ 00062 00063 //! @brief Create a ChessboardWidget object. 00064 ChessboardWidget(void); 00065 //! @brief Destructor. 00066 virtual ~ChessboardWidget(); 00067 00068 //@} 00069 00070 private: 00071 static void S_draw_pawn_hook(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white); 00072 static void S_draw_rook_hook(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white); 00073 static void S_draw_knight_hook(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white); 00074 static void S_draw_bishop_hook(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white); 00075 static void S_draw_queen_hook(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white); 00076 static void S_draw_king_hook(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white); 00077 static void S_draw_hud_layer_hook(CwChessboard* chessboard, cairo_t* cr, gint sside, guint hud); 00078 static gboolean S_draw_hud_square_hook(CwChessboard* chessboard, cairo_t* cr, gint col, gint row, gint sside, guint hud); 00079 static void S_draw_border_hook(CwChessboard* chessboard); 00080 static void S_draw_turn_indicator_hook(CwChessboard* chessboard, gboolean white, gboolean on); 00081 static void S_on_cursor_left_chessboard_hook(CwChessboard* chessboard, gint prev_col, gint prev_row); 00082 static void S_on_cursor_entered_square_hook(CwChessboard* chessboard, gint prev_col, gint prev_row, gint col, gint row); 00083 00084 /** @name Events* / 00085 //@{ 00086 00087 protected: 00088 /** @brief Called when the mouse button is pressed while on the chessboard widget. 00089 * 00090 * This function should be overridden. See the example tstcpp.cc in the source code for an example. 00091 * / 00092 virtual bool on_button_press_event(GdkEventButton* event) { return Gtk::DrawingArea::on_button_press_event(event); } 00093 00094 /** @brief Called when the mouse button is released again. 00095 * 00096 * This function should be overridden. See the example tstcpp.cc in the source code for an example. 00097 * / 00098 virtual bool on_button_release_event(GdkEventButton* event) { return Gtk::DrawingArea::on_button_release_event(event); } 00099 00100 /** @brief Called when the mouse pointer left the chessboard. 00101 * 00102 * @param prev_col : The column of the last square. 00103 * @param prev_row : The row of the last square. 00104 * / 00105 virtual void on_cursor_left_chessboard(gint prev_col, gint prev_row) 00106 { Dout(dc::notice, "Calling on_cursor_left_chessboard(" << prev_col << ", " << prev_row << ")"); } 00107 00108 /** @brief Called when the mouse pointer entered a new square. 00109 * 00110 * @param prev_col : The column of the last square, or -1 if we entered from outside the chessboard. 00111 * @param prev_row : The row of the last square, or -1 if we entered from outside the chessboard. 00112 * @param col : The column of the entered square. 00113 * @param row : The row of the entered square. 00114 * / 00115 virtual void on_cursor_entered_square(gint prev_col, gint prev_row, gint col, gint row) 00116 { Dout(dc::notice, "Calling on_cursor_entered_square(" << prev_col << ", " << prev_row << ", " << col << ", " << row << ")"); } 00117 00118 //@} 00119 00120 /** @name Drawing primitives* / 00121 //@{ 00122 00123 /** @brief Called to draw a pawn. 00124 * 00125 * The default calls #cw_chessboard_draw_pawn. 00126 * / 00127 virtual void draw_pawn(cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white) 00128 { cw_chessboard_draw_pawn(M_chessboard, cr, x, y, sside, white); } 00129 00130 /** @brief Called to draw a rook. 00131 * 00132 * The default calls #cw_chessboard_draw_rook. 00133 * / 00134 virtual void draw_rook(cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white) 00135 { cw_chessboard_draw_rook(M_chessboard, cr, x, y, sside, white); } 00136 00137 /** @brief Called to draw a knight. 00138 * 00139 * The default calls #cw_chessboard_draw_knight. 00140 * / 00141 virtual void draw_knight(cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white) 00142 { cw_chessboard_draw_knight(M_chessboard, cr, x, y, sside, white); } 00143 00144 /** @brief Called to draw a bishop. 00145 * 00146 * The default calls #cw_chessboard_draw_bishop. 00147 * / 00148 virtual void draw_bishop(cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white) 00149 { cw_chessboard_draw_bishop(M_chessboard, cr, x, y, sside, white); } 00150 00151 /** @brief Called to draw a queen. 00152 * 00153 * The default calls #cw_chessboard_draw_queen. 00154 * / 00155 virtual void draw_queen(cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white) 00156 { cw_chessboard_draw_queen(M_chessboard, cr, x, y, sside, white); } 00157 00158 /** @brief Called to draw a king. 00159 * 00160 * The default calls #cw_chessboard_draw_king. 00161 * / 00162 virtual void draw_king(cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white) 00163 { cw_chessboard_draw_king(M_chessboard, cr, x, y, sside, white); } 00164 00165 /** @brief Draw the HUD layer. 00166 * 00167 * This is a layer in between the background (existing of the 64 squares with 00168 * a single color) and the layer with the pieces. It can be used to add some 00169 * texture to the background. 00170 * 00171 * If the HUD layer is active, then this function is called 00172 * whenever the widget is resized. 00173 * 00174 * @param cr : A cairo drawing context. 00175 * @param sside : The size of one side of a square, in pixels. 00176 * @param hud : The HUD index number, see the detailed documentation on the \ref index "main page" for more info. 00177 * 00178 * The default calls #cw_chessboard_default_draw_hud_layer. 00179 * 00180 * @sa enable_hud_layer, disable_hud_layer 00181 * / 00182 virtual void draw_hud_layer(cairo_t* cr, gint sside, guint hud) 00183 { cw_chessboard_default_draw_hud_layer(M_chessboard, cr, sside, hud); } 00184 00185 /** @brief Draw a single HUD square at \a col, \a row. 00186 * 00187 * This function is called by @ref draw_hud_layer "ChessboardWidget::draw_hud_layer" for each square. 00188 * You can use it if you don't override #draw_hud_layer. 00189 * 00190 * @param cr : A cairo drawing context. 00191 * @param col : The column of the square. 00192 * @param row : The row of the square. 00193 * @param sside : The size of one side of the square, in pixels. 00194 * @param hud : The HUD index number, see the detailed documentation of \ref index "main page" for more info. 00195 * 00196 * @returns TRUE if anything was drawn at all, FALSE if the HUD square is fully transparent. 00197 * 00198 * The default calls #cw_chessboard_default_draw_hud_square. 00199 * / 00200 virtual gboolean draw_hud_square(cairo_t* cr, gint col, gint row, gint sside, guint hud) 00201 { return cw_chessboard_default_draw_hud_square(M_chessboard, cr, col, row, sside, hud); } 00202 00203 /** @brief Draw the border around the chessboard. 00204 * 00205 * This function is called when the border is first drawn, and every time the chessboard is resized. 00206 * The width of the drawn border should be the value returned by CwChessboardClass::calc_board_border_width. 00207 * 00208 * The default calls #cw_chessboard_default_draw_border. 00209 * 00210 * @sa set_draw_border 00211 * / 00212 virtual void draw_border(void) 00213 { return cw_chessboard_default_draw_border(M_chessboard); } 00214 00215 /** @brief Draw the indicator that indicates whose turn it is. 00216 * 00217 * This function is called every time the border is redrawn, 00218 * as well as every time #set_draw_turn_indicators is called. 00219 * 00220 * @param white True if the indicator of the white color has to be drawn. 00221 * @param on True if the indictor is on, false if it is off. 00222 * 00223 * The default calls #cw_chessboard_default_draw_turn_indicator. 00224 * 00225 * @sa set_draw_border, set_draw_turn_indicators 00226 * / 00227 virtual void draw_turn_indicator(gboolean white, gboolean on) 00228 { return cw_chessboard_default_draw_turn_indicator(M_chessboard, white, on); } 00229 00230 //@} 00231 00232 public: 00233 00234 // Typedefs 00235 00236 /** @typedef ColorHandle 00237 * @brief A color handle used for background markers. 00238 * 00239 * The five least significant bits determine the color 00240 * from a user defined color palet, used by the background squares 00241 * and markers. A value of zero meaning the default background value 00242 * for that square, or no marker - respectively. 00243 * 00244 * @sa allocate_color_handle_rgb, allocate_color_handle, free_color_handle, 00245 * set_background_color, get_background_color, set_background_colors, 00246 * get_background_colors, set_marker_color, get_marker_color 00247 * / 00248 typedef CwChessboardColorHandle ColorHandle; 00249 00250 /** @typedef code_t 00251 * @brief A code to specify a chess piece. 00252 * 00253 * One of the following constants: 00254 * #empty_square, #black_pawn, #white_pawn, #black_rook, #white_rook, #black_knight, #white_knight, 00255 * #black_bishop, #white_bishop, #black_queen, #white_queen, #black_king or #white_king. 00256 * 00257 * @sa set_square, floating_piece, get_floating_piece 00258 * / 00259 typedef CwChessboardCode code_t; 00260 00261 /** @name Accessors* / 00262 //@{ 00263 00264 //! @brief The side of a square in pixels. 00265 gint sside(void) const { return M_chessboard->sside; } 00266 /** @brief The x coordinate of the top-left pixel of square a1. 00267 * 00268 * If the board is flipped, then the x coordinate of the top-left pixel of square h8 is returned. 00269 * In other words, this value is not depending on whether or not the board is flipped. 00270 * / 00271 gint top_left_a1_x(void) const { return M_chessboard->top_left_a1_x; } 00272 /** @brief The y coordinate of the top-left pixel of square a1. 00273 * 00274 * If the board is flipped, then the y coordinate of the top-left pixel of square h8 is returned. 00275 * In other words, this value is not depending on whether or not the board is flipped. 00276 * / 00277 gint top_left_a1_y(void) const { return M_chessboard->top_left_a1_y; } 00278 00279 //@} 00280 00281 /** @name Public Conversion Functions* / 00282 //@{ 00283 00284 /** @brief Convert a (\a col, \a row) pair to the top-left coordinates of the corresponding square, relative to the top-left of the widget. 00285 * 00286 * @param col : A column, in the range [0, 7]. 00287 * @param row : A row, in the range [0, 7]. 00288 * @param x : A reference to where the x-coordinate of the result will be written to. 00289 * @param y : A reference to where the y-coordinate of the result will be written to. 00290 * / 00291 void colrow2xy(gint col, gint row, gint& x, gint& y) const 00292 { cw_chessboard_colrow2xy(M_chessboard, col, row,& x,& y); } 00293 00294 /** @brief Convert an x-coordinate to the column number that it matches. 00295 * 00296 * If the x coordinate falls outside the board, then the returned value 00297 * will be outside the range [0, 7]. 00298 * 00299 * @param x : An x coordinate, relative to the left-side of the widget. 00300 * 00301 * @returns A column number. 00302 * / 00303 gint x2col(gdouble x) const 00304 { return cw_chessboard_x2col(M_chessboard, x); } 00305 00306 /** @brief Convert a y-coordinate to the row number that it matches. 00307 * 00308 * If the y coordinate falls outside the board, then the returned value 00309 * will be outside the range [0, 7]. 00310 * 00311 * @param y : A y coordinate, relative to the top-side of the widget. 00312 * 00313 * @returns A row number. 00314 * / 00315 gint y2row(gdouble y) const 00316 { return cw_chessboard_y2row(M_chessboard, y); } 00317 00318 /** @brief Test if a given column and row are on the chessboard. 00319 * 00320 * @param col : A column, in the range [0, 7]. 00321 * @param row : A row, in the range [0, 7]. 00322 * 00323 * @returns True if (col, row) falls inside the chessboard. 00324 * / 00325 static gboolean is_inside_board(gint col, gint row) 00326 { return !((col | row) & ~0x7); } 00327 00328 //@} 00329 00330 /** @name Chess Position* / 00331 //@{ 00332 00333 /** @brief Change the piece on a square. 00334 * 00335 * Change or remove the piece on the square (\a col, \a row), 00336 * by replacing the contents of the square with \a code. 00337 * This does not change any other attribute of the square, 00338 * like it's background color or marker. 00339 * 00340 * @param col : A column [0..7] 00341 * @param row : A row [0..7] 00342 * @param code : A #code_t. 00343 * / 00344 void set_square(gint col, gint row, code_t code) 00345 { cw_chessboard_set_square(M_chessboard, col, row, code); } 00346 00347 /** @brief Get what is currently on a square. 00348 * 00349 * Get the chess piece code for the square at (\a col, \a row). 00350 * / 00351 code_t get_square(gint col, gint row) const 00352 { return cw_chessboard_get_square(M_chessboard, col, row); } 00353 00354 //@} 00355 00356 /** @name Border* / 00357 //@{ 00358 00359 /** @brief Set the boolean which determines whether or not the chessboard widget draws a border around the chessboard. 00360 * 00361 * Default: TRUE (draw border). 00362 * 00363 * @param draw : Boolean, determining if the border should be drawn. 00364 * 00365 * @sa draw_border 00366 * / 00367 void set_draw_border(gboolean draw) 00368 { cw_chessboard_set_draw_border(M_chessboard, draw); } 00369 00370 /** @brief Get the boolean that determines whether or not the chessboard widget draws a border around the chessboard. 00371 * 00372 * @returns <code>TRUE</code> if the border is being drawn. 00373 * 00374 * @sa set_draw_border 00375 * / 00376 gboolean get_draw_border(void) const 00377 { return cw_chessboard_get_draw_border(M_chessboard); } 00378 00379 /** @brief Set the boolean which determines whether or not to draw turn indicators. 00380 * 00381 * Indicators will only be drawn if also the border is drawn. 00382 * Default: TRUE (draw indicators). 00383 * 00384 * @param draw Boolean, determining if the indicators should be drawn. 00385 * 00386 * @sa set_draw_border, draw_turn_indicator 00387 * / 00388 void set_draw_turn_indicators(gboolean draw) 00389 { return cw_chessboard_set_draw_turn_indicators(M_chessboard, draw); } 00390 00391 /** @brief Get the boolean which determines whether or not to draw turn indicators. 00392 * 00393 * @sa set_draw_turn_indicators 00394 * / 00395 gboolean get_draw_turn_indicators(void) const 00396 { return cw_chessboard_get_draw_turn_indicators(M_chessboard); } 00397 00398 /** @brief Set the color of the active turn indicator. 00399 * 00400 * Default: TRUE 00401 * 00402 * @param white TRUE if whites turn indicator should be active. 00403 * 00404 * @sa set_draw_turn_indicators 00405 * / 00406 void set_active_turn_indicator(gboolean white) 00407 { return cw_chessboard_set_active_turn_indicator(M_chessboard, white); } 00408 00409 /** @brief Get the boolean which determines whether whites or black turn indicator is active. 00410 * 00411 * @sa set_active_turn_indicator 00412 * / 00413 gboolean get_active_turn_indicator(void) const 00414 { return cw_chessboard_get_active_turn_indicator(M_chessboard); } 00415 00416 /** @brief Set the boolean which determines whether white is playing bottom up or top down. 00417 * 00418 * Default: FALSE (white plays upwards). 00419 * 00420 * @param flip Boolean, determining if white plays upwards or not. 00421 * / 00422 void set_flip_board(gboolean flip) 00423 { return cw_chessboard_set_flip_board(M_chessboard, flip); } 00424 00425 /** @brief Get the boolean which determines whether white is playing bottom up or top down. 00426 * 00427 * @sa set_flip_board 00428 * / 00429 gboolean get_flip_board(void) const 00430 { return cw_chessboard_get_flip_board(M_chessboard); } 00431 00432 /** @brief Set the calc_board_border_width function. 00433 * 00434 * Change the function that calculates the border width as function of the size of the squares. 00435 * 00436 * @param new_calc_board_border_width : The new function. 00437 * 00438 * @sa CwChessboardClass::calc_board_border_width 00439 * / 00440 void set_calc_board_border_width(gint (*new_calc_board_border_width)(CwChessboard const*, gint)) 00441 { 00442 CW_CHESSBOARD_GET_CLASS(M_chessboard)->calc_board_border_width = new_calc_board_border_width; 00443 } 00444 //@} 00445 00446 /** @name Colors* / 00447 //@{ 00448 00449 /** @brief Set the color of the dark squares. 00450 * 00451 * Set the background color of the dark squares (a1, c1 etc). 00452 * Default: light green. 00453 * 00454 * @param color : The new color of the dark squares. 00455 * / 00456 void set_dark_square_color(GdkColor const& color) 00457 { cw_chessboard_set_dark_square_color(M_chessboard,& color); } 00458 00459 /** @brief Set the color of the light squares. 00460 * 00461 * Set the background color of the light squares (b1, d1 etc). 00462 * Default: yellow/white. 00463 * 00464 * @param color : The new color of the light squares. 00465 * / 00466 void set_light_square_color(GdkColor const& color) 00467 { cw_chessboard_set_light_square_color(M_chessboard,& color); } 00468 00469 /** @brief Set the color of the border around the chessboard. 00470 * 00471 * @param color : The new color of the border. 00472 * 00473 * @sa get_border_color, set_draw_border 00474 * / 00475 void set_border_color(GdkColor const& color) 00476 { cw_chessboard_set_border_color(M_chessboard,& color); } 00477 00478 /** @brief Set the fill color of the white chess pieces. 00479 * 00480 * Default: white 00481 * 00482 * @param color : The new fill color of the white pieces. 00483 * / 00484 void set_white_fill_color(GdkColor const& color) 00485 { cw_chessboard_set_white_fill_color(M_chessboard,& color); } 00486 00487 /** @brief Set the line color of the white chess pieces. 00488 * 00489 * Default: black 00490 * 00491 * @param color : The new line color of the white pieces. 00492 * / 00493 void set_white_line_color(GdkColor const& color) 00494 { cw_chessboard_set_white_line_color(M_chessboard,& color); } 00495 00496 /** @brief Set the fill color of the black chess pieces. 00497 * 00498 * Default: black 00499 * 00500 * @param color : The new fill color of the black pieces. 00501 * / 00502 void set_black_fill_color(GdkColor const& color) 00503 { cw_chessboard_set_black_fill_color(M_chessboard,& color); } 00504 00505 /** @brief Set the line color of the black chess pieces. 00506 * 00507 * Default: white 00508 * 00509 * @param color : The new line color of the black pieces. 00510 * / 00511 void set_black_line_color(GdkColor const& color) 00512 { cw_chessboard_set_black_line_color(M_chessboard,& color); } 00513 00514 /** @brief Retrieve the current background color of the dark squares. 00515 * 00516 * @param color : Pointer to the output variable. 00517 * 00518 * @sa set_dark_square_color 00519 * / 00520 void get_dark_square_color(GdkColor& color) const 00521 { cw_chessboard_get_dark_square_color(M_chessboard,& color); } 00522 00523 /** @brief Retrieve the current background color of the light squares. 00524 * 00525 * @param color : Pointer to the output variable. 00526 * 00527 * @sa set_light_square_color 00528 * / 00529 void get_light_square_color(GdkColor& color) const 00530 { cw_chessboard_get_light_square_color(M_chessboard,& color); } 00531 00532 /** @brief Retrieve the current color of the border around the chessboard. 00533 * 00534 * @param color : Pointer to the output variable. 00535 * 00536 * @sa set_border_color 00537 * / 00538 void get_border_color(GdkColor& color) const 00539 { cw_chessboard_get_border_color(M_chessboard,& color); } 00540 00541 /** @brief Retrieve the current fill color of the white chess pieces. 00542 * 00543 * @param color : Pointer to the output variable. 00544 * 00545 * @sa set_white_fill_color 00546 * / 00547 void get_white_fill_color(GdkColor& color) const 00548 { cw_chessboard_get_white_fill_color(M_chessboard,& color); } 00549 00550 /** @brief Retrieve the current line color of the white chess pieces. 00551 * 00552 * @param color : Pointer to the output variable. 00553 * 00554 * @sa set_white_line_color 00555 * / 00556 void get_white_line_color(GdkColor& color) const 00557 { cw_chessboard_get_white_line_color(M_chessboard,& color); } 00558 00559 /** @brief Retrieve the current fill color of the black chess pieces. 00560 * 00561 * @param color : Pointer to the output variable. 00562 * 00563 * @sa set_black_fill_color 00564 * / 00565 void get_black_fill_color(GdkColor& color) const 00566 { cw_chessboard_get_black_fill_color(M_chessboard,& color); } 00567 00568 /** @brief Retrieve the current line color of the black chess pieces. 00569 * 00570 * @param color : Pointer to the output variable. 00571 * 00572 * @sa set_black_line_color 00573 * / 00574 void get_black_line_color(GdkColor& color) const 00575 { cw_chessboard_get_black_line_color(M_chessboard,& color); } 00576 00577 /** @brief Allocate a new ColorHandle. 00578 * 00579 * Simultaneous, there can be at most 31 different colors. 00580 * It is the responsibility of the user to free the colors if they are no longer used. 00581 * 00582 * @param red : The red component of the color in the range [0...1]. 00583 * @param green : The green component of the color in the range [0...1]. 00584 * @param blue : The blue component of the color in the range [0...1]. 00585 * 00586 * @returns A color handle that can be used with #set_background_color and #set_marker_color. 00587 * 00588 * @sa allocate_color_handle, free_color_handle 00589 * / 00590 ColorHandle allocate_color_handle_rgb(gdouble red, gdouble green, gdouble blue) 00591 { return cw_chessboard_allocate_color_handle_rgb(M_chessboard, red, green, blue); } 00592 00593 /** @brief Allocate a new CwChessboardColorHandle. 00594 * 00595 * From more information, see #allocate_color_handle_rgb. 00596 * 00597 * @param color : The color to allocate. 00598 * 00599 * @returns A color handle that can be used with #set_background_color and #set_marker_color. 00600 * 00601 * @sa free_color_handle 00602 * / 00603 ColorHandle allocate_color_handle(GdkColor const& color) 00604 { return cw_chessboard_allocate_color_handle(M_chessboard,& color); } 00605 00606 /** @brief Free up the color handle \a handle, so it can be reused. 00607 * 00608 * @param handle : A color handle as returned by allocate_color_handle_rgb or allocate_color_handle. 00609 * 00610 * @sa allocate_color_handle_rgb, allocate_color_handle 00611 * / 00612 void free_color_handle(ColorHandle handle) 00613 { cw_chessboard_free_color_handle(M_chessboard, handle); } 00614 00615 /** @brief Set the background color of the square at \a col, \a row. 00616 * 00617 * @param col : The column of the square. 00618 * @param row : The row of the square. 00619 * @param handle : A color handle as returned by #allocate_color_handle_rgb or 00620 * #allocate_color_handle. A handle with a value of 0 means the 00621 * default background color. 00622 * / 00623 void set_background_color(gint col, gint row, ColorHandle handle) 00624 { cw_chessboard_set_background_color(M_chessboard, col, row, handle); } 00625 00626 /** @brief Get the current background color handle. 00627 * 00628 * Convenience function. 00629 * 00630 * @param col : The column of the square. 00631 * @param row : The row of the square. 00632 * 00633 * @returns The handle that was passed to #set_background_color 00634 * for this square, or 0 if the square is not associated 00635 * with a color handle. 00636 * / 00637 ColorHandle get_background_color(gint col, gint row) const 00638 { return cw_chessboard_get_background_color(M_chessboard, col, row); } 00639 00640 /** @brief Set new background colors of any number of squares. 00641 * 00642 * @param handles : Array of 64 ColorHandles. 00643 * A handle with a value of 0 means the default background color. 00644 * / 00645 void set_background_colors(ColorHandle const* handles) 00646 { cw_chessboard_set_background_colors(M_chessboard, handles); } 00647 00648 /** @brief Get all background colors handles. 00649 * 00650 * Fill the array \a handles with the current color handles. 00651 * 00652 * @param handles : The output array. Should be an array of 64 ColorHandles. 00653 * / 00654 void get_background_colors(ColorHandle* handles) const 00655 { cw_chessboard_get_background_colors(M_chessboard, handles); } 00656 00657 //@} 00658 00659 /** @name Floating Pieces* / 00660 //@{ 00661 00662 /** @brief Add a new floating chess piece. 00663 * 00664 * This function displays a chess piece with code \a code at widget coordinates (\a x, \a y). 00665 * Half the side of a square will be subtracted from the coordinates passed, and 00666 * the result truncated, in order to determine where to draw the top-left corner 00667 * of the piece. The result is that (\a x, \a y) is more or less the center of the piece. 00668 * 00669 * Setting \a pointer_device will cause gdk_window_get_pointer to be called 00670 * after the next redraw has finished. This is needed to receive the next motion 00671 * notify event with GDK_POINTER_MOTION_HINT_MASK being used. 00672 * 00673 * There may only be one floating piece related the pointer device at a time. 00674 * If there is already another floating piece related to the pointer device 00675 * then the value of \a pointer_device is ignored. 00676 * 00677 * @param code : The code of the chess piece to be drawn. 00678 * @param x : The center x-coordinate of the piece. 00679 * @param y : The center y-coordinate of the piece. 00680 * @param pointer_device : Whether this piece is under the pointer device or not. 00681 * 00682 * @returns A handle that can be passed to each of the functions below. 00683 * 00684 * @sa get_floating_piece, remove_floating_piece, move_floating_piece 00685 * / 00686 gint add_floating_piece(code_t code, gdouble x, gdouble y, gboolean pointer_device) 00687 { return cw_chessboard_add_floating_piece(M_chessboard, code, x, y, pointer_device); } 00688 00689 /** @brief Move a floating chess piece to a new position. 00690 * 00691 * Move a floating piece with handle \a handle to the new widget 00692 * coordinates at (\a x, \a y). \a handle must be a handle as 00693 * returned by #add_floating_piece. 00694 * 00695 * @param handle : The floating piece handle. 00696 * @param x : The new x coordinate. 00697 * @param y : The new y coordinate. 00698 * 00699 * @sa add_floating_piece 00700 * / 00701 void move_floating_piece(gint handle, gdouble x, gdouble y) 00702 { cw_chessboard_move_floating_piece(M_chessboard, handle, x, y); } 00703 00704 /** @brief Remove a floating piece. 00705 * 00706 * Delete the floating piece with handle \a handle. 00707 * \a handle must be a handle as returned by #add_floating_piece. 00708 * 00709 * @param handle : The floating piece handle. 00710 * / 00711 void remove_floating_piece(gint handle) 00712 { cw_chessboard_remove_floating_piece(M_chessboard, handle); } 00713 00714 /** @brief Determine what piece a given floating piece is. 00715 * 00716 * Get the code_t of the floating piece represented by \a handle. 00717 * \a handle must be a handle as returned by #add_floating_piece. 00718 * 00719 * @param handle : The floating piece handle. 00720 * / 00721 code_t get_floating_piece(gint handle) const 00722 { return cw_chessboard_get_floating_piece(M_chessboard, handle); } 00723 00724 //@} 00725 00726 /** @name HUD Layers* / 00727 //@{ 00728 00729 /** @brief Active a HUD layer. 00730 * 00731 * HUD 0 lays between the background and the pieces. 00732 * HUD 1 lays above the pieces. 00733 * A custom HUD layer can be created by setting CwChessboardClass::draw_hud_layer. 00734 * 00735 * @param hud : The HUD layer (0 or 1). 00736 * 00737 * @sa CwChessboardClass::draw_hud_layer, disable_hud_layer 00738 * / 00739 void enable_hud_layer(guint hud) 00740 { cw_chessboard_enable_hud_layer(M_chessboard, hud); } 00741 00742 /** @brief Disable the HUD layer again. 00743 * 00744 * Used resources are returned to the system. 00745 * 00746 * @param hud : The HUD layer (0 or 1). 00747 * 00748 * @sa enable_hud_layer 00749 * / 00750 void disable_hud_layer(guint hud) 00751 { cw_chessboard_disable_hud_layer(M_chessboard, hud); } 00752 00753 //@} 00754 00755 /** @name Markers* / 00756 //@{ 00757 00758 /** @brief Change the color of the marker. 00759 * 00760 * Add a marker to, or remove a marker from the square at \a col, \a row. 00761 * 00762 * @param col : The column of the square. 00763 * @param row : The row of the square. 00764 * @param mahandle : A color handle as returned by #allocate_color_handle_rgb or #allocate_color_handle. 00765 * A handle with a value of 0 removes the marker (if any was there). 00766 * / 00767 void set_marker_color(gint col, gint row, ColorHandle mahandle) 00768 { cw_chessboard_set_marker_color(M_chessboard, col, row, mahandle); } 00769 00770 /** @brief Get marker color. 00771 * 00772 * Convenience function. 00773 * 00774 * @param col : The column of the square. 00775 * @param row : The row of the square. 00776 * 00777 * @returns The handle that was passed to #set_marker_color 00778 * for this square, or 0 if the square doesn't have a marker. 00779 * / 00780 ColorHandle get_marker_color(gint col, gint row) const 00781 { return cw_chessboard_get_marker_color(M_chessboard, col, row); } 00782 00783 /** @brief Set the marker thickness. 00784 * 00785 * This is a value between 0 and 0.5. 00786 * 00787 * @param thickness : The thickness of the marker as fraction of sside. Range [0...0.5] 00788 * 00789 * @sa get_marker_thickness 00790 * / 00791 void set_marker_thickness(gdouble thickness) 00792 { return cw_chessboard_set_marker_thickness(M_chessboard, thickness); } 00793 00794 /** @brief Get the current marker thickness as fraction of sside. 00795 * 00796 * @sa set_marker_thickness 00797 * / 00798 gdouble get_marker_thickness(void) const 00799 { return cw_chessboard_get_marker_thickness(M_chessboard); } 00800 00801 /** @brief Choose whether markers should be drawn below or above HUD layer 0. 00802 * 00803 * Markers can be drawn directly below or directly above HUD layer 0. 00804 * 00805 * @param below : TRUE when markers should be drawn below HUD layer 0. 00806 * / 00807 void set_marker_level(gboolean below) 00808 { return cw_chessboard_set_marker_level(M_chessboard, below); } 00809 00810 //@} 00811 00812 /** @name Cursor* / 00813 //@{ 00814 00815 /** @brief Show the cursor. 00816 * 00817 * This high-lights the square under the mouse by drawing a 00818 * square with a configurable thickness and color. 00819 * 00820 * @sa set_cursor_thickness, get_cursor_thickness 00821 * / 00822 void show_cursor(void) 00823 { cw_chessboard_show_cursor(M_chessboard); } 00824 00825 /** @brief Hide the cursor. 00826 * 00827 * @sa show_cursor 00828 * / 00829 void hide_cursor(void) 00830 { cw_chessboard_hide_cursor(M_chessboard); } 00831 00832 /** @brief Set the thickness of the cursor. 00833 * 00834 * This is a value between 0 and 0.5. 00835 * 00836 * @param thickness : The thickness of the cursor as fraction of sside. Range [0...0.5] 00837 * 00838 * @sa get_cursor_thickness 00839 * / 00840 void set_cursor_thickness(gdouble thickness) 00841 { cw_chessboard_set_cursor_thickness(M_chessboard, thickness); } 00842 00843 /** @brief Get the current cursor thickness as fraction of sside. 00844 * 00845 * @sa set_cursor_thickness 00846 * / 00847 gdouble get_cursor_thickness(void) const 00848 { return cw_chessboard_get_cursor_thickness(M_chessboard); } 00849 00850 /** @brief Set the color of the cursor. 00851 * 00852 * @param color : The color to be used for the cursor. 00853 * / 00854 void set_cursor_color(GdkColor const& color) 00855 { cw_chessboard_set_cursor_color(M_chessboard,& color); } 00856 00857 /** @brief Get the current cursor color. 00858 * 00859 * @param color : Pointer to the output variable. 00860 * / 00861 void get_cursor_color(GdkColor& color) const 00862 { cw_chessboard_get_cursor_color(M_chessboard,& color); } 00863 00864 //@} 00865 00866 /** @name Arrows* / 00867 //@{ 00868 00869 /** @brief Draw an arrow on the board. 00870 * 00871 * @param begin_col : The column of the starting square. 00872 * @param begin_row : The row of the starting square. 00873 * @param end_col : The column of the ending square. 00874 * @param end_row : The row of the ending square. 00875 * @param color : The color to draw the arrow in. 00876 * 00877 * @returns A handle that can be used to remove the arrow again. 00878 * 00879 * @sa remove_arrow 00880 * / 00881 gpointer add_arrow(gint begin_col, gint begin_row, gint end_col, gint end_row, GdkColor const& color) 00882 { return cw_chessboard_add_arrow(M_chessboard, begin_col, begin_row, end_col, end_row,& color); } 00883 00884 /** @brief Remove a previously added arrow. 00885 * 00886 * @param ptr : The arrow handle as returned by #add_arrow. 00887 * / 00888 void remove_arrow(gpointer ptr) 00889 { cw_chessboard_remove_arrow(M_chessboard, ptr); } 00890 00891 //@} 00892 }; 00893 00894 } // namespace cwmm 00895 00896 #endif // CHESSBOARD_H