cwmm::ChessPositionWidget Class Reference

A chessboard widget that is synchronized with a ChessPosition . More...

#include <ChessPositionWidget.h>

Inheritance diagram for cwmm::ChessPositionWidget:

List of all members.

Public Types

typedef CwChessboardColorHandle ColorHandle
typedef CwChessboardCode code_t

Public Member Functions

Constructor

 ChessPositionWidget (Gtk::Window* drawable, Glib::RefPtr< cwchess::Promotion > promotion=Glib::RefPtr< cwchess::Promotion >(new cwchess::Promotion))
 Constructor.
ChessPostion methods : Position setup

For a description of these methods, see the member functions with the same name in cwchess::ChessPosition.

void clear (void)
 See cwchess::ChessPosition::clear.
void initial_position (void)
 See cwchess::ChessPosition::initial_position.
bool skip_move (void)
 See cwchess::ChessPosition::skip_move.
void to_move (cwchess::Color const& color)
 See cwchess::ChessPosition::to_move.
bool set_en_passant (cwchess::Index const& index)
 See cwchess::ChessPosition::set_en_passant.
void swap_colors (void)
 See cwchess::ChessPosition::swap_colors.
bool place (cwchess::Code const& code, cwchess::Index const& index)
 See cwchess::ChessPosition::place.
bool load_FEN (std::string const& FEN)
 See cwchess::ChessPosition::load_FEN.
ChessPostion methods : Game play

For a description of these methods, see the member functions with the same name in cwchess::ChessPosition.

bool execute (cwchess::Move const& move)
 See cwchess::ChessPosition::execute.
Position setup

void set_position (cwchess::ChessPosition const& chess_position)
void clipboard_paste (void)
 Paste a position from the clipboard.
Accessors

ChessPosition const&  get_position (void) const
 Return a const reference to the current position.
void clipboard_copy (void) const
 Copy a position to the clipboard.
Events

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.
virtual bool on_button_release (gint col, gint row, GdkEventButton const* event)
 Called when a mouse button is released.
virtual void on_cursor_left_chessboard (gint prev_col, gint prev_row)
 Called when the mouse pointer left the chessboard.
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.
Signals

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.
sigc::signal< void, gint, gint,
cwchess::ChessPosition const & >&  
signal_dropped (void)
 Return handler for events signaling that the user dropped a piece.
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.
sigc::signal< void,
cwchess::Move const
&, cwchess::ChessPosition
const & >&  
signal_illegal (void)
 Return handler for events signaling that the user attempted an illegal move.

Protected Member Functions

virtual void on_menu_placepiece_black_pawn (void)
virtual void on_menu_placepiece_black_rook (void)
virtual void on_menu_placepiece_black_knight (void)
virtual void on_menu_placepiece_black_bishop (void)
virtual void on_menu_placepiece_black_queen (void)
virtual void on_menu_placepiece_black_king (void)
virtual void on_menu_placepiece_white_pawn (void)
virtual void on_menu_placepiece_white_rook (void)
virtual void on_menu_placepiece_white_knight (void)
virtual void on_menu_placepiece_white_bishop (void)
virtual void on_menu_placepiece_white_queen (void)
virtual void on_menu_placepiece_white_king (void)
virtual void on_menu_placepiece_nothing (void)
virtual void on_menu_allow_en_passant_capture (void)
virtual void on_menu_piece_has_moved (void)
virtual void on_menu_copy_FEN (void)
virtual void on_menu_paste_FEN (void)
virtual void on_menu_swap_colors (void)
virtual void on_menu_initial_position (void)
virtual void on_menu_clear_board (void)
virtual void on_menu_to_move_white (void)
virtual void on_menu_to_move_black (void)
virtual void on_clipboard_get (Gtk::SelectionData& selection_data, guint info)
virtual void on_clipboard_clear (void)
virtual void on_clipboard_received (Glib::ustring const& text)
virtual void on_clipboard_received_targets (Glib::StringArrayHandle const& targets_array)

Protected Attributes

'Edit Position' mode related variables

cwchess::Index M_placepiece_index
 The square that a new piece is being placed on with the popup menu, in 'Edit Position' mode.
Gtk::Window*  M_drawable
 A pointer to a drawable used for it's colormap (for the icons in the popup menu).
Gtk::Menu*  M_MenuPopup
 An instance of the popup menu to place new pieces.
Glib::RefPtr< Gtk::UIManager > M_refUIManager
 Reference to a UIManager.
Glib::RefPtr< Gtk::ActionGroup > M_refActionGroup
 Reference to a ActionGroup.
Glib::RefPtr< Gtk::IconFactory > M_refIconFactory
 Reference to a IconFactory.
Glib::RefPtr< Gtk::RadioAction > M_refToMoveWhite_action
 Reference to RadioAction for ToMoveWhite.
Glib::RefPtr< Gtk::RadioAction > M_refToMoveBlack_action
 Reference to RadioAction for ToMoveBlack.
Glib::RefPtr< Gtk::ToggleAction > M_refPieceHasMoved_action
 Reference to ToggleAction for PieceHasMoved.
Glib::RefPtr< Gtk::ToggleAction > M_refAllowEnPassantCapture_action
 Reference to ToggleAction for AllowEnPassantCapture.
sigc::connection M_PieceHasMoved_connection
 The HasMoved ToggleAction connection.
sigc::connection M_AllowEnPassantCapture_connection
 The AllowEnPassantCapture ToggleAction connection.

Get/Set Widget Modes



typedef unsigned int widget_mode_type
 The type of the builtin widget modes.
static widget_mode_type const mode_edit_position = 0
 The value used for the 'Edit Position' mode.
static widget_mode_type const mode_edit_game = 1
 The value used for the 'Edit Game' mode.
static widget_mode_type const mode_disabled = 2
 The value used for the 'Widget disabled' mode.
widget_mode_type get_widget_mode (void) const
 Return the current widget mode.
void set_widget_mode (widget_mode_type widget_mode)
 Set the widget mode.

Detailed Description

A chessboard widget that is synchronized with a ChessPosition .

This is the object that you want to use (instead of ChessboardWidget).

It combines cwmm::ChessboardWidget with cwchess::ChessPosition, keeping the position on both synchronized.

Apart from the reimplemented ChessPosition methods listed above, every other method of both base classes are public except:

This object has three builtin modes:

In game play mode, the user can only pick up pieces of the color that is to move, and only do legal moves (illegal moves cause the piece to be put back where it came from).

In position setup mode, the user can move pieces arbitrarily around and use a right-click popup menu to select and place new pieces on the board, clear a square, select which color is to move, copy and paste to/from the clipboard, swap colors, clear the board, set up the initial position, mark a pawn as being allowed to taken en passant and mark rooks or kings has having moved.

Finally, the 'disable widget' mode just means that the user is not allowed to pick up or place pieces. This would be the typical state to put the widget in while the user is waiting for the opponent to move.

In order to allow a flexible interaction with the widget, the following signals and events are provided:

Definition at line 89 of file ChessPositionWidget.h.


Constructor & Destructor Documentation

cwmm::ChessPositionWidget::ChessPositionWidget ( Gtk::Window*   drawable,
Glib::RefPtr< cwchess::Promotion promotion = Glib::RefPtr<cwchess::Promotion>(new cwchess::Promotion) 
) [inline]

Constructor.

Parameters:
drawable : A drawable, usually the main window of the application.
promotion : An object derived from Promotion that handles pawn promotions.

Definition at line 178 of file ChessPositionWidget.h.


Member Function Documentation

virtual bool cwmm::ChessPositionWidget::on_button_press ( gint  col,
gint  row,
GdkEventButton const*   event 
) [inline, virtual]

Called when a mouse button is pressed while the mouse is on the chessboard.

Parameters:
col : The column of the square the mouse is on.
row : The row of the square the mouse is on.
event : The button press event.

Useful members of the event are:

  • event->button : The number of the button that is pressed.
  • event->type : GDK_BUTTON_PRESS for a normal click, GDK_2BUTTON_PRESS for a double click.
  • event->x, event->y : The exact pixel coordinates where was clicked.

The default does nothing but return false.

This function should normally return false. If it returns true then the event is considered to be completely handled and nothing else will be done.

In case of a double click, this function is called three times. First with event->type == GDK_BUTTON_PRESS, followed by a call to on_button_release. Next again with event->type == GDK_BUTTON_PRESS and then with event->type == GDK_2BUTTON_PRESS. Finally on_button_release will be called a second time. Therefore, a call to this function with event->type == GDK_BUTTON_PRESS and a subsequent on_button_release at the same coordinates should be a non-operation (if you want to use double clicks too).

Reimplemented in MyChessboardWidget.

Definition at line 534 of file ChessPositionWidget.h.

virtual bool cwmm::ChessPositionWidget::on_button_release ( gint  col,
gint  row,
GdkEventButton const*   event 
) [inline, virtual]

Called when a mouse button is released.

Parameters:
col : The column of the square the mouse is on, or -1 if the mouse is outside the chessboard.
row : The row of the square the mouse is on, or -1 if the mouse is outside the chessboard.
event : The button release event.

Useful members of the event are:

  • event->button : The number of the button that is released.
  • event->x, event->y : The exact pixel coordinates where it is released.

The default does nothing but return false.

This function should normally return false. If it returns true then the event is considered to be completely handled and nothing else will be done.

Reimplemented in MyChessboardWidget.

Definition at line 552 of file ChessPositionWidget.h.

virtual void cwmm::ChessPositionWidget::on_cursor_entered_square ( gint  prev_col,
gint  prev_row,
gint  col,
gint  row 
) [inline, virtual]

Called when the mouse pointer entered a new square.

The default does nothing.

Reimplemented from cwmm::ChessboardWidget.

Definition at line 564 of file ChessPositionWidget.h.

virtual void cwmm::ChessPositionWidget::on_cursor_left_chessboard ( gint  prev_col,
gint  prev_row 
) [inline, virtual]

Called when the mouse pointer left the chessboard.

The default does nothing.

Reimplemented from cwmm::ChessboardWidget.

Definition at line 558 of file ChessPositionWidget.h.

void cwmm::ChessPositionWidget::set_position ( cwchess::ChessPosition const&   chess_position  )  [inline]

Copy a new position from chess_position.

Parameters:
chess_position : The new position to use.

Definition at line 489 of file ChessPositionWidget.h.

Referenced by load_FEN().

sigc::signal<void, gint, gint, cwchess::ChessPosition const&>& cwmm::ChessPositionWidget::signal_dropped ( void   )  [inline]

Return handler for events signaling that the user dropped a piece.

This signal is generated whenever the mouse button is released after picking up a piece.

Definition at line 589 of file ChessPositionWidget.h.

sigc::signal<void, cwchess::Move const&, cwchess::ChessPosition const&>& cwmm::ChessPositionWidget::signal_illegal ( void   )  [inline]

Return handler for events signaling that the user attempted an illegal move.

This signal is only generated while the widget is in 'Game Play' mode. Note that dropping a piece on the square where it was picked up, or dropping it outside the board is not an illegal move, but is considered to be an abort of 'pick up and move' action.

Definition at line 613 of file ChessPositionWidget.h.

sigc::signal<void, cwchess::Move const&, cwchess::ChessPosition const&, cwchess::ChessPosition const&>& cwmm::ChessPositionWidget::signal_moved ( void   )  [inline]

Return handler for events signaling that the user did a (legal) chess move.

This signal is only generated while the widget is in 'Game Play' mode. If the user picks up a piece and drops it on a different square and this is a legal move, then the move is executed (the ChessPosition is updated) after which this signal is generated.

Be aware that callback functions should return promptly or the GUI would freeze. If, for example, you want the computer to play the other color then the callback function would merely put the widget in 'Disabled' mode, set a flag that it is the turn of the computer and return immediately. In general, calculating a reply move would be done in a seperate thread.

Definition at line 604 of file ChessPositionWidget.h.

sigc::signal<void, cwchess::Index const&, cwchess::ChessPosition const&>& cwmm::ChessPositionWidget::signal_picked_up ( void   )  [inline]

Return handler for events signaling that the user picked up a piece.

This signal is generated whenever the user picks up a piece. It can happen in both 'Position Setup' as well as 'Game Play' mode.

Note that a double-click on a piece will cause the piece to be picked up and dropped, then picked up again, then the double click event will be generated and upon final release of the mouse button the piece will be dropped again. You have to take into account that this happens when dealing with double clicks.

Definition at line 582 of file ChessPositionWidget.h.


The documentation for this class was generated from the following files:

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