ChessPositionWidget.h
Go to the documentation of this file.
1 // cwchessboard -- A C++ chessboard tool set for gtkmm
2 //
3 //! @file ChessPositionWidget.h This file contains the declaration of class ChessPositionWidget.
4 //
5 // Copyright (C) 2008 - 2010, by
6 //
7 // Carlo Wood, Run on IRC <carlo@alinoe.com>
8 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
9 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
10 //
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 2 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 
24 #ifndef CHESSPOSITIONWIDGET_H
25 #define CHESSPOSITIONWIDGET_H
26 
27 #ifndef USE_PCH
28 #include <boost/shared_ptr.hpp>
29 #include <gtkmm/menu.h>
30 #include <gtkmm/uimanager.h>
31 #include <gtkmm/iconfactory.h>
32 #include <gtkmm/window.h>
33 #endif
34 
35 #include "ChessboardWidget.h"
36 #include "ChessPosition.h"
37 #include "Promotion.h"
38 
39 namespace cwmm {
40 
41 /** @brief A chessboard widget that is synchronized with a \link cwchess::ChessPosition ChessPosition \endlink.
42 *
43  * This is the object that you want to use (instead of ChessboardWidget).
44 *
45  * It combines cwmm::ChessboardWidget with cwchess::ChessPosition,
46  * keeping the position on both synchronized.
47 *
48  * Apart from the reimplemented ChessPosition methods listed above, every other method
49  * of both base classes are public <em>except</em>:
50 *
51  * - ChessboardWidget::set_square : Use \link ChessPositionWidget::place place \endlink instead.
52  * - ChessboardWidget::get_square : Use \link cwchess::ChessPosition::piece_at piece_at \endlink instead.
53  * - ChessboardWidget::set_active_turn_indicator : Use \link ChessPositionWidget::to_move(cwchess::Color const&) to_move \endlink instead.
54  * - ChessboardWidget::get_active_turn_indicator : Use \link cwchess::ChessPosition::to_move() to_move \endlink instead.
55 *
56  * This object has three builtin modes:
57  * - Position setup (see #mode_edit_position).
58  * - Game play (see #mode_edit_game).
59  * - Disable widget (see #mode_disabled).
60 *
61  * In game play mode, the user can only pick up pieces of the color
62  * that is to move, and only do legal moves (illegal moves cause
63  * the piece to be put back where it came from).
64 *
65  * In position setup mode, the user can move pieces arbitrarily around
66  * and use a right-click popup menu to select and place new pieces
67  * on the board, clear a square, select which color is to move,
68  * copy and paste to/from the clipboard, swap colors, clear the
69  * board, set up the initial position, mark a pawn as being allowed
70  * to taken en passant and mark rooks or kings has having moved.
71 *
72  * Finally, the 'disable widget' mode just means that the user is
73  * not allowed to pick up or place pieces. This would be the typical
74  * state to put the widget in while the user is waiting for the
75  * opponent to move.
76 *
77  * In order to allow a flexible interaction with the widget, the
78  * following signals and events are provided:
79 *
80  * - Mouse leaves the chessboard (see #on_cursor_left_chessboard).
81  * - Mouse enters a (different) square (see #on_cursor_entered_square).
82  * - A mouse button was pressed (see #on_button_press).
83  * - A mouse button was released (see #on_button_release).
84  * - A piece was picked up (see \link ChessPositionWidget::signal_picked_up signal_picked_up \endlink).
85  * - A piece was dropped (see \link ChessPositionWidget::signal_dropped signal_dropped \endlink).
86  * - A (legal) move was executed (see \link ChessPositionWidget::signal_moved signal_moved \endlink).
87  * - An illegal move was attempted (see \link ChessPositionWidget::signal_illegal signal_illegal \endlink).
88 * /
90  public:
91  /** @name Get/Set Widget Modes* /
92  //@{
93 
94  //! The type of the builtin widget modes.
95  typedef unsigned int widget_mode_type;
96  //! The value used for the 'Edit Position' mode.
97  static widget_mode_type const mode_edit_position = 0;
98  //! The value used for the 'Edit Game' mode.
99  static widget_mode_type const mode_edit_game = 1;
100  //! The value used for the 'Widget disabled' mode.
101  static widget_mode_type const mode_disabled = 2;
102 
103  //! Return the current widget mode.
104  widget_mode_type get_widget_mode(void) const { return M_widget_mode; }
105  //! Set the widget mode.
106  void set_widget_mode(widget_mode_type widget_mode) { M_widget_mode = widget_mode; }
107 
108  //@}
109 
110  private:
111  //! The current widget mode.
112  widget_mode_type M_widget_mode;
113  //! The signal generator for 'piece pick up' events.
114  sigc::signal<void, cwchess::Index const&, cwchess::ChessPosition const&> M_signal_picked_up;
115  //! The signal generator for 'piece drop' events.
116  sigc::signal<void, gint, gint, cwchess::ChessPosition const&> M_signal_dropped;
117  //! The handle of the floating piece under the mouse pointer, if any.
118  gint M_floating_piece_handle;
119  //! Temporary storage for copied positions.
120  Glib::ustring M_clipboard_content;
121  //! Set when trying primrary clipboard contents.
122  bool M_trying_primary;
123 
124  /** @name 'Edit Game' mode related variables* /
125  //@{
126 
127  //! The square that a piece was picked up from.
128  cwchess::Index M_move_from;
129  //! The object used to promote pawns.
130  Glib::RefPtr<cwchess::Promotion> M_promotion;
131  //! The signal generator for legal moves.
132  sigc::signal<void, cwchess::Move const&, cwchess::ChessPosition const&, cwchess::ChessPosition const&> M_signal_moved;
133  //! The signal generator for illegal moves.
134  sigc::signal<void, cwchess::Move const&, cwchess::ChessPosition const&> M_signal_illegal;
135 
136  //@}
137 
138  /** @name 'Edit Position' mode related variables* /
139  //@{
140 
141  protected:
142  //! The square that a new piece is being placed on with the popup menu, in 'Edit Position' mode.
144  //! A pointer to a drawable used for it's colormap (for the icons in the popup menu).
145  Gtk::Window* M_drawable;
146  //! An instance of the popup menu to place new pieces.
147  Gtk::Menu* M_MenuPopup;
148  //! Reference to a UIManager.
149  Glib::RefPtr<Gtk::UIManager> M_refUIManager;
150  //! Reference to a ActionGroup.
151  Glib::RefPtr<Gtk::ActionGroup> M_refActionGroup;
152  //! Reference to a IconFactory.
153  Glib::RefPtr<Gtk::IconFactory> M_refIconFactory;
154  //! Reference to RadioAction for ToMoveWhite.
155  Glib::RefPtr<Gtk::RadioAction> M_refToMoveWhite_action;
156  //! Reference to RadioAction for ToMoveBlack.
157  Glib::RefPtr<Gtk::RadioAction> M_refToMoveBlack_action;
158  //! Reference to ToggleAction for PieceHasMoved.
159  Glib::RefPtr<Gtk::ToggleAction> M_refPieceHasMoved_action;
160  //! Reference to ToggleAction for AllowEnPassantCapture.
161  Glib::RefPtr<Gtk::ToggleAction> M_refAllowEnPassantCapture_action;
162  //! The HasMoved ToggleAction connection.
163  sigc::connection M_PieceHasMoved_connection;
164  //! The AllowEnPassantCapture ToggleAction connection.
166 
167  //@}
168 
169  public:
170  /** @name Constructor* /
171  //@{
172 
173  /** @brief Constructor.
174  *
175  * @param drawable : A drawable, usually the main window of the application.
176  * @param promotion : An object derived from Promotion that handles pawn promotions.
177  * /
178  ChessPositionWidget(Gtk::Window* drawable, Glib::RefPtr<cwchess::Promotion> promotion = Glib::RefPtr<cwchess::Promotion>(new cwchess::Promotion)) :
179  M_floating_piece_handle(-1), M_widget_mode(mode_edit_position), M_promotion(promotion), M_MenuPopup(NULL), M_drawable(drawable), M_trying_primary(false)
180  {
181  // Continue initialization when realized.
182  drawable->signal_realize().connect(sigc::mem_fun(this,& ChessPositionWidget::initialize_menus));
183  }
184 
185  //@}
186 
187  private:
188  void initialize_menus(void);
189  bool popup_menu(GdkEventButton* event, int col, int row);
190  void popup_deactivated(void);
191  void update_paste_status(void);
192 
193  protected:
194  virtual void on_menu_placepiece_black_pawn(void);
195  virtual void on_menu_placepiece_black_rook(void);
196  virtual void on_menu_placepiece_black_knight(void);
197  virtual void on_menu_placepiece_black_bishop(void);
198  virtual void on_menu_placepiece_black_queen(void);
199  virtual void on_menu_placepiece_black_king(void);
200  virtual void on_menu_placepiece_white_pawn(void);
201  virtual void on_menu_placepiece_white_rook(void);
202  virtual void on_menu_placepiece_white_knight(void);
203  virtual void on_menu_placepiece_white_bishop(void);
204  virtual void on_menu_placepiece_white_queen(void);
205  virtual void on_menu_placepiece_white_king(void);
206  virtual void on_menu_placepiece_nothing(void);
207  virtual void on_menu_allow_en_passant_capture(void);
208  virtual void on_menu_piece_has_moved(void);
209  virtual void on_menu_copy_FEN(void);
210  virtual void on_menu_paste_FEN(void);
211  virtual void on_menu_swap_colors(void);
212  virtual void on_menu_initial_position(void);
213  virtual void on_menu_clear_board(void);
214  virtual void on_menu_to_move_white(void);
215  virtual void on_menu_to_move_black(void);
216  virtual void on_clipboard_get(Gtk::SelectionData& selection_data, guint info);
217  virtual void on_clipboard_clear(void);
218  virtual void on_clipboard_received(Glib::ustring const& text);
219  virtual void on_clipboard_received_targets(Glib::StringArrayHandle const& targets_array);
220 
221  /** @name ChessPostion methods : Hidden base class members.
222  *
223  * ChessboardWidget::set_square : Use \link ChessPositionWidget::place place \endlink instead.
224  * ChessboardWidget::get_square : Use \link cwchess::ChessPosition::piece_at piece_at \endlink instead.
225  * ChessboardWidget::set_active_turn_indicator : Use \link ChessPositionWidget::to_move(cwchess::Color const&) to_move \endlink instead.
226  * ChessboardWidget::get_active_turn_indicator : Use \link cwchess::ChessPosition::to_move() to_move \endlink instead.
227  * /
228  //@{
229 
230  protected:
235 
236  //@}
237 
238  public:
239  using ChessboardWidget::trackable;
246 
247  /** @name ChessPostion methods : Position setup
248  *
249  * For a description of these methods, see the member functions
250  * with the same name in cwchess::ChessPosition.
251  * /
252  //@{
253 
254  using ChessPosition::set_half_move_clock;
255  using ChessPosition::set_full_move_number;
256  using ChessPosition::set_has_moved;
257  using ChessPosition::clear_has_moved;
258 
259  //! See cwchess::ChessPosition::clear.
260  void clear(void) { ChessPosition::clear(); sync(); }
261  //! See cwchess::ChessPosition::initial_position.
262  void initial_position(void) { ChessPosition::initial_position(); sync(); }
263  //! See cwchess::ChessPosition::skip_move.
264  bool skip_move(void) { bool result = ChessPosition::skip_move(); set_active_turn_indicator(to_move().is_white()); return result; }
265  //! See cwchess::ChessPosition::to_move.
266  void to_move(cwchess::Color const& color) { ChessPosition::to_move(color); set_active_turn_indicator(to_move().is_white()); }
267  //! See cwchess::ChessPosition::set_en_passant.
268  bool set_en_passant(cwchess::Index const& index) { ChessPosition::set_en_passant(index); set_active_turn_indicator(to_move().is_white()); }
269  //! See cwchess::ChessPosition::swap_colors.
270  void swap_colors(void) { ChessPosition::swap_colors(); sync(); }
271  //! See cwchess::ChessPosition::place.
272  bool place(cwchess::Code const& code, cwchess::Index const& index) { if (ChessPosition::place(code, index)) set_square(index.col(), index.row(), code); }
273  //! See cwchess::ChessPosition::load_FEN.
274  bool load_FEN(std::string const& FEN);
275 
276  //@}
277 
278  /** @name ChessPostion methods : Accessors
279  *
280  * For a description of these methods, see the member functions
281  * with the same name in cwchess::ChessPosition.
282  * /
283  //@{
284 
285  public:
286  using ChessPosition::piece_at;
287  using ChessPosition::to_move;
288  using ChessPosition::half_move_clock;
289  using ChessPosition::full_move_number;
290  using ChessPosition::castle_flags;
291  using ChessPosition::en_passant;
292  using ChessPosition::all;
293 
294  //@}
295 
296  /** @name ChessPostion methods : Visitors
297  *
298  * For a description of these methods, see the member functions
299  * with the same name in cwchess::ChessPosition.
300  * /
301  //@{
302 
303  public:
304  using ChessPosition::FEN;
305  using ChessPosition::candidates_table_offset;
306  using ChessPosition::candidates;
307  using ChessPosition::reachables;
308  using ChessPosition::defendables;
309  using ChessPosition::index_of_king;
310  using ChessPosition::check;
311  using ChessPosition::double_check;
312  using ChessPosition::moves;
313  using ChessPosition::legal;
314 
315  //@}
316 
317  /** @name ChessPostion methods : Iterators
318  *
319  * For a description of these methods, see the member functions
320  * with the same name in cwchess::ChessPosition.
321  * /
322  //@{
323 
324  public:
325  using ChessPosition::piece_begin;
326  using ChessPosition::piece_end;
327  using ChessPosition::move_begin;
328  using ChessPosition::move_end;
329 
330  //@}
331 
332  /** @name ChessPostion methods : Game play
333  *
334  * For a description of these methods, see the member functions
335  * with the same name in cwchess::ChessPosition.
336  * /
337  //@{
338 
339  //! See cwchess::ChessPosition::execute.
340  bool execute(cwchess::Move const& move);
341 
342  //@}
343 
344  /** @name ChessboardWidget methods : Accessors
345  *
346  * For a description of these methods, see the member functions
347  * with the same name in cwmm::ChessboardWidget.
348  * /
349  //@{
350 
351  public:
355 
356  //@}
357 
358  /** @name ChessboardWidget methods : Border
359  *
360  * For a description of these methods, see the member functions
361  * with the same name in cwmm::ChessboardWidget.
362  * /
363  //@{
364 
365  public:
373 
374  //@}
375 
376  /** @name ChessboardWidget methods : Border
377  *
378  * For a description of these methods, see the member functions
379  * with the same name in cwmm::ChessboardWidget.
380  * /
381  //@{
382 
383  public:
405 
406  //@}
407 
408  /** @name ChessboardWidget methods : Floating Pieces
409  *
410  * For a description of these methods, see the member functions
411  * with the same name in cwmm::ChessboardWidget.
412  * /
413  //@{
414 
415  public:
420 
421  //@}
422 
423  /** @name ChessboardWidget methods : HUD Layers
424  *
425  * For a description of these methods, see the member functions
426  * with the same name in cwmm::ChessboardWidget.
427  * /
428  //@{
429 
430  public:
433 
434  //@}
435 
436  /** @name ChessboardWidget methods : Markers
437  *
438  * For a description of these methods, see the member functions
439  * with the same name in cwmm::ChessboardWidget.
440  * /
441  //@{
442 
443  public:
449 
450  //@}
451 
452  /** @name ChessboardWidget methods : Cursor
453  *
454  * For a description of these methods, see the member functions
455  * with the same name in cwmm::ChessboardWidget.
456  * /
457  //@{
458 
459  public:
466 
467  //@}
468 
469  /** @name ChessboardWidget methods : Arrows
470  *
471  * For a description of these methods, see the member functions
472  * with the same name in cwmm::ChessboardWidget.
473  * /
474  //@{
475 
476  public:
479 
480  //@}
481 
482  /** @name Position setup* /
483  //@{
484 
485  /** Copy a new position from \a chess_position.
486  *
487  * @param chess_position : The new position to use.
488  * /
489  void set_position(cwchess::ChessPosition const& chess_position) {* static_cast<cwchess::ChessPosition*>(this) = chess_position; sync(); }
490 
491  //! Paste a position from the clipboard.
492  void clipboard_paste(void);
493 
494  //@}
495 
496  /** @name Accessors* /
497  //@{
498 
499  //! Return a const reference to the current position.
500  ChessPosition const& get_position(void) const { return* this; }
501 
502  //! Copy a position to the clipboard.
503  void clipboard_copy(void) const;
504 
505  //@}
506 
507  /** @name Events* /
508  //@{
509 
510  /** @brief Called when a mouse button is pressed while the mouse is on the chessboard.
511  *
512  * @param col : The column of the square the mouse is on.
513  * @param row : The row of the square the mouse is on.
514  * @param event : The button press event.
515  *
516  * Useful members of the event are:
517  * - <code>event->button</code> : The number of the button that is pressed.
518  * - <code>event->type</code> : <code>GDK_BUTTON_PRESS</code> for a normal click, <code>GDK_2BUTTON_PRESS</code> for a double click.
519  * - <code>event->x</code>, <code>event->y</code> : The exact pixel coordinates where was clicked.
520  *
521  * The default does nothing but return false.
522  *
523  * This function should normally return false. If it returns true then
524  * the event is considered to be completely handled and nothing else
525  * will be done.
526  *
527  * In case of a double click, this function is called three times.
528  * First with <code>event->type == GDK_BUTTON_PRESS</code>, followed by a call to #on_button_release.
529  * Next again with <code>event->type == GDK_BUTTON_PRESS</code> and then with <code>event->type == GDK_2BUTTON_PRESS</code>.
530  * Finally #on_button_release will be called a second time. Therefore, a call to this
531  * function with <code>event->type == GDK_BUTTON_PRESS</code> and a subsequent on_button_release at
532  * the same coordinates should be a non-operation (if you want to use double clicks too).
533  * /
534  virtual bool on_button_press(gint col, gint row, GdkEventButton const* event) { return false; }
535 
536  /** @brief Called when a mouse button is released.
537  *
538  * @param col : The column of the square the mouse is on, or -1 if the mouse is outside the chessboard.
539  * @param row : The row of the square the mouse is on, or -1 if the mouse is outside the chessboard.
540  * @param event : The button release event.
541  *
542  * Useful members of the event are:
543  * - <code>event->button</code> : The number of the button that is released.
544  * - <code>event->x</code>, <code>event->y</code> : The exact pixel coordinates where it is released.
545  *
546  * The default does nothing but return false.
547  *
548  * This function should normally return false. If it returns true then
549  * the event is considered to be completely handled and nothing else
550  * will be done.
551  * /
552  virtual bool on_button_release(gint col, gint row, GdkEventButton const* event) { return false; }
553 
554  /** @brief Called when the mouse pointer left the chessboard.
555  *
556  * The default does nothing.
557  * /
558  virtual void on_cursor_left_chessboard(gint prev_col, gint prev_row) { }
559 
560  /** @brief Called when the mouse pointer entered a new square.
561  *
562  * The default does nothing.
563  * /
564  virtual void on_cursor_entered_square(gint prev_col, gint prev_row, gint col, gint row) { }
565 
566  //@}
567 
568  /** @name Signals* /
569  //@{
570 
571  /** @brief Return handler for events signaling that the user picked up a piece.
572  *
573  * This signal is generated whenever the user picks up a piece.
574  * It can happen in both 'Position Setup' as well as 'Game Play' mode.
575  *
576  * Note that a double-click on a piece will cause the piece to be picked
577  * up and dropped, then picked up again, then the double click event
578  * will be generated and upon final release of the mouse button the
579  * piece will be dropped again. You have to take into account that this
580  * happens when dealing with double clicks.
581  * /
582  sigc::signal<void, cwchess::Index const&, cwchess::ChessPosition const&>& signal_picked_up(void) { return M_signal_picked_up; }
583 
584  /** @brief Return handler for events signaling that the user dropped a piece.
585  *
586  * This signal is generated whenever the mouse button is released after
587  * picking up a piece.
588  * /
589  sigc::signal<void, gint, gint, cwchess::ChessPosition const&>& signal_dropped(void) { return M_signal_dropped; }
590 
591  /** @brief Return handler for events signaling that the user did a (legal) chess move.
592  *
593  * This signal is only generated while the widget is in 'Game Play' mode.
594  * If the user picks up a piece and drops it on a different square and
595  * this is a legal move, then the move is executed (the ChessPosition is updated)
596  * after which this signal is generated.
597  *
598  * Be aware that callback functions should return promptly or the GUI would freeze.
599  * If, for example, you want the computer to play the other color then the
600  * callback function would merely put the widget in 'Disabled' mode, set
601  * a flag that it is the turn of the computer and return immediately.
602  * In general, calculating a reply move would be done in a seperate thread.
603  * /
604  sigc::signal<void, cwchess::Move const&, cwchess::ChessPosition const&, cwchess::ChessPosition const&>& signal_moved(void) { return M_signal_moved; }
605 
606  /** @brief Return handler for events signaling that the user attempted an illegal move.
607  *
608  * This signal is only generated while the widget is in 'Game Play' mode.
609  * Note that dropping a piece on the square where it was picked up, or
610  * dropping it outside the board is <em>not</em> an illegal move, but
611  * is considered to be an abort of 'pick up and move' action.
612  * /
613  sigc::signal<void, cwchess::Move const&, cwchess::ChessPosition const&>& signal_illegal(void) { return M_signal_illegal; }
614 
615  //@}
616 
617  protected_notdocumented:
618  virtual bool on_button_press_event(GdkEventButton* event);
619  virtual bool on_button_release_event(GdkEventButton* event);
620 
621  private:
622  void sync(void);
623 };
624 
625 } // namespace cwmm
626 
627 #endif // CHESSPOSITIONWIDGET_H
void colrow2xy(gint col, gint row, gint& x, gint& y) const
Convert a (col, row) pair to the top-left coordinates of the corresponding square, relative to the top-left of the widget.
void get_white_line_color(GdkColor& color) const
Retrieve the current line color of the white chess pieces.
void set_draw_border(gboolean draw)
Set the boolean which determines whether or not the chessboard widget draws a border around the chess...
void set_active_turn_indicator(gboolean white)
Set the color of the active turn indicator.
static widget_mode_type const mode_edit_position
The value used for the& #39;Edit Position&#39; mode.
void set_background_colors(ColorHandle const* handles)
Set new background colors of any number of squares.
void free_color_handle(ColorHandle handle)
Free up the color handle handle, so it can be reused.
Glib::RefPtr< Gtk::ToggleAction > M_refAllowEnPassantCapture_action
Reference to ToggleAction for AllowEnPassantCapture.
Glib::RefPtr< Gtk::IconFactory > M_refIconFactory
Reference to a IconFactory.
sigc::signal< void, cwchess::Index const& , cwchess::ChessPosition const & > & signal_picked_up(void)
Return handler for events signaling that the user picked up a piece.
code_t get_square(gint col, gint row) const
Get what is currently on a square.
void get_border_color(GdkColor& color) const
Retrieve the current color of the border around the chessboard.
void set_square(gint col, gint row, code_t code)
Change the piece on a square.
void clipboard_copy(void) const
Copy a position to the clipboard.
void disable_hud_layer(guint hud)
Disable the HUD layer again.
void clipboard_paste(void)
Paste a position from the clipboard.
sigc::connection M_PieceHasMoved_connection
The HasMoved ToggleAction connection.
void set_calc_board_border_width(gint(*new_calc_board_border_width)(CwChessboard const* , gint))
Set the calc_board_border_width function.
void set_white_line_color(GdkColor const& color)
Set the line color of the white chess pieces.
void initial_position(void)
See cwchess::ChessPosition::initial_position.
gint top_left_a1_x(void) const
The x coordinate of the top-left pixel of square a1.
static gboolean is_inside_board(gint col, gint row)
Test if a given column and row are on the chessboard.
sigc::signal< void, gint, gint, cwchess::ChessPosition const & > & signal_dropped(void)
Return handler for events signaling that the user dropped a piece.
bool load_FEN(std::string const& FEN)
See cwchess::ChessPosition::load_FEN.
A chess move in a particular chess position.
Definition: Move.h:44
gboolean get_active_turn_indicator(void) const
Get the boolean which determines whether whites or black turn indicator is active.
void set_marker_thickness(gdouble thickness)
Set the marker thickness.
A gtkmm chessboard widget.
gdouble get_marker_thickness(void) const
Get the current marker thickness as fraction of sside.
Glib::RefPtr< Gtk::ActionGroup > M_refActionGroup
Reference to a ActionGroup.
ChessPosition const & get_position(void) const
Return a const reference to the current position.
void set_light_square_color(GdkColor const& color)
Set the color of the light squares.
widget_mode_type get_widget_mode(void) const
Return the current widget mode.
void get_black_line_color(GdkColor& color) const
Retrieve the current line color of the black chess pieces.
virtual bool on_button_release(gint col, gint row, GdkEventButton const* event)
Called when a mouse button is released.
gint add_floating_piece(code_t code, gdouble x, gdouble y, gboolean pointer_device)
Add a new floating chess piece.
void show_cursor(void)
Show the cursor.
void set_draw_turn_indicators(gboolean draw)
Set the boolean which determines whether or not to draw turn indicators.
Gtk::Menu * M_MenuPopup
An instance of the popup menu to place new pieces.
gint top_left_a1_y(void) const
The y coordinate of the top-left pixel of square a1.
void to_move(cwchess::Color const& color)
See cwchess::ChessPosition::to_move.
ColorHandle get_marker_color(gint col, gint row) const
Get marker color.
void set_border_color(GdkColor const& color)
Set the color of the border around the chessboard.
gint sside(void) const
The side of a square in pixels.
gint x2col(gdouble x) const
Convert an x-coordinate to the column number that it matches.
The index of a chess square.
Definition: Index.h:211
A chessboard widget that is synchronized with a ChessPosition .
sigc::signal< void, cwchess::Move const& , cwchess::ChessPosition const & > & signal_illegal(void)
Return handler for events signaling that the user attempted an illegal move.
int col(void) const
Returns the column.
Definition: Index.h:337
void clear(void)
See cwchess::ChessPosition::clear.
void swap_colors(void)
See cwchess::ChessPosition::swap_colors.
Glib::RefPtr< Gtk::RadioAction > M_refToMoveWhite_action
Reference to RadioAction for ToMoveWhite.
bool place(cwchess::Code const& code, cwchess::Index const& index)
See cwchess::ChessPosition::place.
bool skip_move(void)
See cwchess::ChessPosition::skip_move.
void hide_cursor(void)
Hide the cursor.
gboolean get_draw_turn_indicators(void) const
Get the boolean which determines whether or not to draw turn indicators.
static widget_mode_type const mode_edit_game
The value used for the& #39;Edit Game&#39; mode.
This file contains the declaration of class Promotion.
bool set_en_passant(cwchess::Index const& index)
See cwchess::ChessPosition::set_en_passant.
ColorHandle get_background_color(gint col, gint row) const
Get the current background color handle.
ChessPosition(void)
Construct an uninitialized position.
Definition: ChessPosition.h:76
virtual void on_cursor_entered_square(gint prev_col, gint prev_row, gint col, gint row)
Called when the mouse pointer entered a new square.
unsigned int widget_mode_type
The type of the builtin widget modes.
void remove_arrow(gpointer ptr)
Remove a previously added arrow.
void get_dark_square_color(GdkColor& color) const
Retrieve the current background color of the dark squares.
ColorHandle allocate_color_handle(GdkColor const& color)
Allocate a new CwChessboardColorHandle.
code_t get_floating_piece(gint handle) const
Determine what piece a given floating piece is.
This file contains the declaration of the gtkmm class ChessboardWidget.
void set_cursor_thickness(gdouble thickness)
Set the thickness of the cursor.
virtual void on_cursor_left_chessboard(gint prev_col, gint prev_row)
Called when the mouse pointer left the chessboard.
CwChessboardCode code_t
A code to specify a chess piece.
int row(void) const
Returns the row.
Definition: Index.h:334
Gtk::Window * M_drawable
A pointer to a drawable used for it&#39;s colormap (for the icons in the popup menu). ...
A namespace for all gtkmm related objects.
void set_black_line_color(GdkColor const& color)
Set the line color of the black chess pieces.
A chess position.
Definition: ChessPosition.h:50
void remove_floating_piece(gint handle)
Remove a floating piece.
Glib::RefPtr< Gtk::UIManager > M_refUIManager
Reference to a UIManager.
void set_marker_level(gboolean below)
Choose whether markers should be drawn below or above HUD layer 0.
A chess piece type including color.
Definition: Code.h:92
void get_background_colors(ColorHandle* handles) const
Get all background colors handles.
void set_widget_mode(widget_mode_type widget_mode)
Set the widget mode.
void set_cursor_color(GdkColor const& color)
Set the color of the cursor.
sigc::connection M_AllowEnPassantCapture_connection
The AllowEnPassantCapture ToggleAction connection.
void set_background_color(gint col, gint row, ColorHandle handle)
Set the background color of the square at col, row.
This file contains the declaration of class ChessPosition.
gint y2row(gdouble y) const
Convert a y-coordinate to the row number that it matches.
static widget_mode_type const mode_disabled
The value used for the& #39;Widget disabled&#39; mode.
std::string FEN(void) const
Return the FEN code for this position.
ChessPositionWidget(Gtk::Window* drawable, Glib::RefPtr< cwchess::Promotion > promotion=Glib::RefPtr< cwchess::Promotion >(new cwchess::Promotion))
Constructor.
cwchess::Index M_placepiece_index
The square that a new piece is being placed on with the popup menu, in& #39;Edit Position&#39; mode...
void set_dark_square_color(GdkColor const& color)
Set the color of the dark squares.
CwChessboardColorHandle ColorHandle
A color handle used for background markers.
void set_marker_color(gint col, gint row, ColorHandle mahandle)
Change the color of the marker.
gboolean get_draw_border(void) const
Get the boolean that determines whether or not the chessboard widget draws a border around the chessb...
A color (black or white).
Definition: Color.h:67
void get_light_square_color(GdkColor& color) const
Retrieve the current background color of the light squares.
gpointer add_arrow(gint begin_col, gint begin_row, gint end_col, gint end_row, GdkColor const& color)
Draw an arrow on the board.
virtual bool on_button_press(gint col, gint row, GdkEventButton const* event)
Called when a mouse button is pressed while the mouse is on the chessboard.
Glib::RefPtr< Gtk::RadioAction > M_refToMoveBlack_action
Reference to RadioAction for ToMoveBlack.
void move_floating_piece(gint handle, gdouble x, gdouble y)
Move a floating chess piece to a new position.
void enable_hud_layer(guint hud)
Active a HUD layer.
gdouble get_cursor_thickness(void) const
Get the current cursor thickness as fraction of sside.
bool execute(cwchess::Move const& move)
See cwchess::ChessPosition::execute.
void set_white_fill_color(GdkColor const& color)
Set the fill color of the white chess pieces.
void set_position(cwchess::ChessPosition const& chess_position)
Color to_move(void) const
Return whose turn it is.
gboolean get_flip_board(void) const
Get the boolean which determines whether white is playing bottom up or top down.
void set_black_fill_color(GdkColor const& color)
Set the fill color of the black chess pieces.
void get_cursor_color(GdkColor& color) const
Get the current cursor color.
void set_flip_board(gboolean flip)
Set the boolean which determines whether white is playing bottom up or top down.
Glib::RefPtr< Gtk::ToggleAction > M_refPieceHasMoved_action
Reference to ToggleAction for PieceHasMoved.
void get_white_fill_color(GdkColor& color) const
Retrieve the current fill color of the white chess pieces.
ColorHandle allocate_color_handle_rgb(gdouble red, gdouble green, gdouble blue)
Allocate a new ColorHandle.
void get_black_fill_color(GdkColor& color) const
Retrieve the current fill color of the black chess pieces.
sigc::signal< void, cwchess::Move const& , cwchess::ChessPosition const& , cwchess::ChessPosition const & > & signal_moved(void)
Return handler for events signaling that the user did a (legal) chess move.

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