Public Types | Protected Member Functions | List of all members
cwmm::ChessPositionWidget Class Reference

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

#include <ChessPositionWidget.h>

Inheritance diagram for cwmm::ChessPositionWidget:
Inheritance graph
[legend]

Public Types

typedef CwChessboardColorHandle ColorHandle
 
typedef CwChessboardCode code_t
 
- Public Types inherited from cwmm::ChessboardWidget
typedef CwChessboardColorHandle ColorHandle
 A color handle used for background markers. More...
 
typedef CwChessboardCode code_t
 A code to specify a chess piece. More...
 

Public Member Functions

Constructor
 ChessPositionWidget (Gtk::Window* drawable, Glib::RefPtr< cwchess::Promotion > promotion=Glib::RefPtr< cwchess::Promotion >(new cwchess::Promotion))
 Constructor. More...
 
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. More...
 
virtual bool on_button_release (gint col, gint row, GdkEventButton const* event)
 Called when a mouse button is released. More...
 
virtual void on_cursor_left_chessboard (gint prev_col, gint prev_row)
 Called when the mouse pointer left the chessboard. More...
 
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. More...
 
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. More...
 
sigc::signal< void, gint, gint, cwchess::ChessPosition const & >&  signal_dropped (void)
 Return handler for events signaling that the user dropped a piece. More...
 
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. More...
 
sigc::signal< void, cwchess::Move const& , cwchess::ChessPosition const & >&  signal_illegal (void)
 Return handler for events signaling that the user attempted an illegal move. More...
 
- Public Member Functions inherited from cwmm::ChessboardWidget
 ChessboardWidget (void)
 Create a ChessboardWidget object.
 
virtual ~ChessboardWidget ()
 Destructor.
 
gint sside (void) const
 The side of a square in pixels.
 
gint top_left_a1_x (void) const
 The x coordinate of the top-left pixel of square a1. More...
 
gint top_left_a1_y (void) const
 The y coordinate of the top-left pixel of square a1. More...
 
void set_square (gint col, gint row, code_t code)
 Change the piece on a square. More...
 
code_t get_square (gint col, gint row) const
 Get what is currently on a square. More...
 
void set_draw_border (gboolean draw)
 Set the boolean which determines whether or not the chessboard widget draws a border around the chessboard. More...
 
gboolean get_draw_border (void) const
 Get the boolean that determines whether or not the chessboard widget draws a border around the chessboard. More...
 
void set_draw_turn_indicators (gboolean draw)
 Set the boolean which determines whether or not to draw turn indicators. More...
 
gboolean get_draw_turn_indicators (void) const
 Get the boolean which determines whether or not to draw turn indicators. More...
 
void set_active_turn_indicator (gboolean white)
 Set the color of the active turn indicator. More...
 
gboolean get_active_turn_indicator (void) const
 Get the boolean which determines whether whites or black turn indicator is active. More...
 
void set_flip_board (gboolean flip)
 Set the boolean which determines whether white is playing bottom up or top down. More...
 
gboolean get_flip_board (void) const
 Get the boolean which determines whether white is playing bottom up or top down. More...
 
void set_calc_board_border_width (gint(*new_calc_board_border_width)(CwChessboard const* , gint))
 Set the calc_board_border_width function. More...
 
void set_dark_square_color (GdkColor const& color)
 Set the color of the dark squares. More...
 
void set_light_square_color (GdkColor const& color)
 Set the color of the light squares. More...
 
void set_border_color (GdkColor const& color)
 Set the color of the border around the chessboard. More...
 
void set_white_fill_color (GdkColor const& color)
 Set the fill color of the white chess pieces. More...
 
void set_white_line_color (GdkColor const& color)
 Set the line color of the white chess pieces. More...
 
void set_black_fill_color (GdkColor const& color)
 Set the fill color of the black chess pieces. More...
 
void set_black_line_color (GdkColor const& color)
 Set the line color of the black chess pieces. More...
 
void get_dark_square_color (GdkColor& color) const
 Retrieve the current background color of the dark squares. More...
 
void get_light_square_color (GdkColor& color) const
 Retrieve the current background color of the light squares. More...
 
void get_border_color (GdkColor& color) const
 Retrieve the current color of the border around the chessboard. More...
 
void get_white_fill_color (GdkColor& color) const
 Retrieve the current fill color of the white chess pieces. More...
 
void get_white_line_color (GdkColor& color) const
 Retrieve the current line color of the white chess pieces. More...
 
void get_black_fill_color (GdkColor& color) const
 Retrieve the current fill color of the black chess pieces. More...
 
void get_black_line_color (GdkColor& color) const
 Retrieve the current line color of the black chess pieces. More...
 
ColorHandle allocate_color_handle_rgb (gdouble red, gdouble green, gdouble blue)
 Allocate a new ColorHandle. More...
 
ColorHandle allocate_color_handle (GdkColor const& color)
 Allocate a new CwChessboardColorHandle. More...
 
void free_color_handle (ColorHandle handle)
 Free up the color handle handle, so it can be reused. More...
 
void set_background_color (gint col, gint row, ColorHandle handle)
 Set the background color of the square at col, row. More...
 
ColorHandle get_background_color (gint col, gint row) const
 Get the current background color handle. More...
 
void set_background_colors (ColorHandle const* handles)
 Set new background colors of any number of squares. More...
 
void get_background_colors (ColorHandle* handles) const
 Get all background colors handles. More...
 
gint add_floating_piece (code_t code, gdouble x, gdouble y, gboolean pointer_device)
 Add a new floating chess piece. More...
 
void move_floating_piece (gint handle, gdouble x, gdouble y)
 Move a floating chess piece to a new position. More...
 
void remove_floating_piece (gint handle)
 Remove a floating piece. More...
 
code_t get_floating_piece (gint handle) const
 Determine what piece a given floating piece is. More...
 
void enable_hud_layer (guint hud)
 Active a HUD layer. More...
 
void disable_hud_layer (guint hud)
 Disable the HUD layer again. More...
 
void set_marker_color (gint col, gint row, ColorHandle mahandle)
 Change the color of the marker. More...
 
ColorHandle get_marker_color (gint col, gint row) const
 Get marker color. More...
 
void set_marker_thickness (gdouble thickness)
 Set the marker thickness. More...
 
gdouble get_marker_thickness (void) const
 Get the current marker thickness as fraction of sside. More...
 
void set_marker_level (gboolean below)
 Choose whether markers should be drawn below or above HUD layer 0. More...
 
void show_cursor (void)
 Show the cursor. More...
 
void hide_cursor (void)
 Hide the cursor. More...
 
void set_cursor_thickness (gdouble thickness)
 Set the thickness of the cursor. More...
 
gdouble get_cursor_thickness (void) const
 Get the current cursor thickness as fraction of sside. More...
 
void set_cursor_color (GdkColor const& color)
 Set the color of the cursor. More...
 
void get_cursor_color (GdkColor& color) const
 Get the current cursor color. More...
 
gpointer add_arrow (gint begin_col, gint begin_row, gint end_col, gint end_row, GdkColor const& color)
 Draw an arrow on the board. More...
 
void remove_arrow (gpointer ptr)
 Remove a previously added arrow. More...
 
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. More...
 
gint x2col (gdouble x) const
 Convert an x-coordinate to the column number that it matches. More...
 
gint y2row (gdouble y) const
 Convert a y-coordinate to the row number that it matches. More...
 

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 Member Functions inherited from cwchess::ChessPosition
void reset_en_passant (void)
 
 ChessPosition (void)
 Construct an uninitialized position.
 
void clear (void)
 Clear the board. More...
 
void initial_position (void)
 Set up the initial position.
 
bool skip_move (void)
 Skip a move. More...
 
void to_move (Color const& color)
 Explicitly set whose turn it is. More...
 
void set_half_move_clock (int count)
 Explicitly set the number of half moves since the last pawn move or capture. More...
 
void set_full_move_number (int move)
 Explicitly set the move number. More...
 
bool set_en_passant (Index const& index)
 Explicity set the en passant information. More...
 
void swap_colors (void)
 Swap colors. More...
 
bool place (Code const& code, Index const& index)
 Place a piece on the board. More...
 
void set_has_moved (Index const& index)
 Specifically specify that a king or rook has already moved. More...
 
void clear_has_moved (Index const& index)
 Specifically specify that a king or rook didn't move yet. More...
 
bool load_FEN (std::string const& FEN)
 Read a FEN code. More...
 
Piece piece_at (Index const& index) const
 Return the Piece on the square index.
 
Piece piece_at (int col, int row) const
 Return the Piece on the square col, row.
 
Color to_move (void) const
 Return whose turn it is.
 
unsigned int half_move_clock (void) const
 Return the half move clock.
 
unsigned int full_move_number (void) const
 Return the full move number.
 
CastleFlags const&  castle_flags (void) const
 Return the castle flag object.
 
EnPassant const&  en_passant (void) const
 Return the en passant object.
 
BitBoard const&  all (Code const& code) const
 Return a BitBoard with bits set for all code, where code may not be 'nothing'.
 
BitBoard const&  all (Color const& color) const
 Return a BitBoard with bits set for all pieces of color color.
 
std::string FEN (void) const
 Return the FEN code for this position.
 
int candidates_table_offset (Type const& type) const
 Return the offset into the candidates_table for type type. More...
 
BitBoard candidates (Index const& index) const
 Return a BitBoard with bits set for all squares that are candidates to move to. More...
 
BitBoard reachables (Index const& index, bool attacked_squares=false) const
 Return a BitBoard with bits set for each square that a piece can reach in one move. More...
 
BitBoard defendables (Code const& code, Index const& index, bool& battery) const
 Return a BitBoard with bits set for each square that a piece defends, or would defend if an exchange was going on there. More...
 
Index index_of_king (Color const& color) const
 Return the index of the king with color color.
 
bool check (void) const
 Return true if the king is in check.
 
bool check (Color const& color) const
 Return true if the king of color color is in check.
 
bool double_check (Color const& color) const
 Return true if the king of color color is in double check.
 
bool has_moved (Index const& index)
 Return true if the king or rook on index has moved or not. More...
 
BitBoard moves (Index const& index) const
 Return a BitBoard with bits set for each square the piece at index can legally go to. More...
 
bool legal (Move const& move) const
 Return true if the move is a legal move.
 
PieceIterator piece_begin (Color const& color) const
 Return an iterator to the first piece of color color. More...
 
PieceIterator piece_end (void) const
 Return an iterator one beyond the last piece.
 
PieceIterator piece_begin (Code const& code) const
 Return an iterator to the first piece with code code. More...
 
MoveIterator move_begin (Index const& index) const
 Return an iterator to the first move of the piece at index index.
 
MoveIterator move_end (void) const
 Return an iterator one beyond the last move.
 
bool execute (Move const& move)
 Execute move move.
 
- Protected Member Functions inherited from cwmm::ChessboardWidget
virtual void draw_pawn (cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
 Called to draw a pawn. More...
 
virtual void draw_rook (cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
 Called to draw a rook. More...
 
virtual void draw_knight (cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
 Called to draw a knight. More...
 
virtual void draw_bishop (cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
 Called to draw a bishop. More...
 
virtual void draw_queen (cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
 Called to draw a queen. More...
 
virtual void draw_king (cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
 Called to draw a king. More...
 
virtual void draw_hud_layer (cairo_t* cr, gint sside, guint hud)
 Draw the HUD layer. More...
 
virtual gboolean draw_hud_square (cairo_t* cr, gint col, gint row, gint sside, guint hud)
 Draw a single HUD square at col, row. More...
 
virtual void draw_border (void)
 Draw the border around the chessboard. More...
 
virtual void draw_turn_indicator (gboolean white, gboolean on)
 Draw the indicator that indicates whose turn it is. More...
 
 ChessboardWidget (void)
 Create a ChessboardWidget object.
 
virtual ~ChessboardWidget ()
 Destructor.
 
gint sside (void) const
 The side of a square in pixels.
 
gint top_left_a1_x (void) const
 The x coordinate of the top-left pixel of square a1. More...
 
gint top_left_a1_y (void) const
 The y coordinate of the top-left pixel of square a1. More...
 
void set_square (gint col, gint row, code_t code)
 Change the piece on a square. More...
 
code_t get_square (gint col, gint row) const
 Get what is currently on a square. More...
 
void set_draw_border (gboolean draw)
 Set the boolean which determines whether or not the chessboard widget draws a border around the chessboard. More...
 
gboolean get_draw_border (void) const
 Get the boolean that determines whether or not the chessboard widget draws a border around the chessboard. More...
 
void set_draw_turn_indicators (gboolean draw)
 Set the boolean which determines whether or not to draw turn indicators. More...
 
gboolean get_draw_turn_indicators (void) const
 Get the boolean which determines whether or not to draw turn indicators. More...
 
void set_active_turn_indicator (gboolean white)
 Set the color of the active turn indicator. More...
 
gboolean get_active_turn_indicator (void) const
 Get the boolean which determines whether whites or black turn indicator is active. More...
 
void set_flip_board (gboolean flip)
 Set the boolean which determines whether white is playing bottom up or top down. More...
 
gboolean get_flip_board (void) const
 Get the boolean which determines whether white is playing bottom up or top down. More...
 
void set_calc_board_border_width (gint(*new_calc_board_border_width)(CwChessboard const* , gint))
 Set the calc_board_border_width function. More...
 
void set_dark_square_color (GdkColor const& color)
 Set the color of the dark squares. More...
 
void set_light_square_color (GdkColor const& color)
 Set the color of the light squares. More...
 
void set_border_color (GdkColor const& color)
 Set the color of the border around the chessboard. More...
 
void set_white_fill_color (GdkColor const& color)
 Set the fill color of the white chess pieces. More...
 
void set_white_line_color (GdkColor const& color)
 Set the line color of the white chess pieces. More...
 
void set_black_fill_color (GdkColor const& color)
 Set the fill color of the black chess pieces. More...
 
void set_black_line_color (GdkColor const& color)
 Set the line color of the black chess pieces. More...
 
void get_dark_square_color (GdkColor& color) const
 Retrieve the current background color of the dark squares. More...
 
void get_light_square_color (GdkColor& color) const
 Retrieve the current background color of the light squares. More...
 
void get_border_color (GdkColor& color) const
 Retrieve the current color of the border around the chessboard. More...
 
void get_white_fill_color (GdkColor& color) const
 Retrieve the current fill color of the white chess pieces. More...
 
void get_white_line_color (GdkColor& color) const
 Retrieve the current line color of the white chess pieces. More...
 
void get_black_fill_color (GdkColor& color) const
 Retrieve the current fill color of the black chess pieces. More...
 
void get_black_line_color (GdkColor& color) const
 Retrieve the current line color of the black chess pieces. More...
 
ColorHandle allocate_color_handle_rgb (gdouble red, gdouble green, gdouble blue)
 Allocate a new ColorHandle. More...
 
ColorHandle allocate_color_handle (GdkColor const& color)
 Allocate a new CwChessboardColorHandle. More...
 
void free_color_handle (ColorHandle handle)
 Free up the color handle handle, so it can be reused. More...
 
void set_background_color (gint col, gint row, ColorHandle handle)
 Set the background color of the square at col, row. More...
 
ColorHandle get_background_color (gint col, gint row) const
 Get the current background color handle. More...
 
void set_background_colors (ColorHandle const* handles)
 Set new background colors of any number of squares. More...
 
void get_background_colors (ColorHandle* handles) const
 Get all background colors handles. More...
 
gint add_floating_piece (code_t code, gdouble x, gdouble y, gboolean pointer_device)
 Add a new floating chess piece. More...
 
void move_floating_piece (gint handle, gdouble x, gdouble y)
 Move a floating chess piece to a new position. More...
 
void remove_floating_piece (gint handle)
 Remove a floating piece. More...
 
code_t get_floating_piece (gint handle) const
 Determine what piece a given floating piece is. More...
 
void enable_hud_layer (guint hud)
 Active a HUD layer. More...
 
void disable_hud_layer (guint hud)
 Disable the HUD layer again. More...
 
void set_marker_color (gint col, gint row, ColorHandle mahandle)
 Change the color of the marker. More...
 
ColorHandle get_marker_color (gint col, gint row) const
 Get marker color. More...
 
void set_marker_thickness (gdouble thickness)
 Set the marker thickness. More...
 
gdouble get_marker_thickness (void) const
 Get the current marker thickness as fraction of sside. More...
 
void set_marker_level (gboolean below)
 Choose whether markers should be drawn below or above HUD layer 0. More...
 
void show_cursor (void)
 Show the cursor. More...
 
void hide_cursor (void)
 Hide the cursor. More...
 
void set_cursor_thickness (gdouble thickness)
 Set the thickness of the cursor. More...
 
gdouble get_cursor_thickness (void) const
 Get the current cursor thickness as fraction of sside. More...
 
void set_cursor_color (GdkColor const& color)
 Set the color of the cursor. More...
 
void get_cursor_color (GdkColor& color) const
 Get the current cursor color. More...
 
gpointer add_arrow (gint begin_col, gint begin_row, gint end_col, gint end_row, GdkColor const& color)
 Draw an arrow on the board. More...
 
void remove_arrow (gpointer ptr)
 Remove a previously added arrow. More...
 
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. More...
 
gint x2col (gdouble x) const
 Convert an x-coordinate to the column number that it matches. More...
 
gint y2row (gdouble y) const
 Convert a y-coordinate to the row number that it matches. More...
 

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.
 
- Protected Attributes inherited from cwmm::CwChessboardPtr
CwChessboard*  M_chessboard
 

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.
 

Additional Inherited Members

- Static Public Member Functions inherited from cwmm::ChessboardWidget
static gboolean is_inside_board (gint col, gint row)
 Test if a given column and row are on the chessboard. More...
 
- Protected Types inherited from cwmm::ChessboardWidget
typedef CwChessboardColorHandle ColorHandle
 A color handle used for background markers. More...
 
typedef CwChessboardCode code_t
 A code to specify a chess piece. More...
 
- Static Protected Member Functions inherited from cwmm::ChessboardWidget
static gboolean is_inside_board (gint col, gint row)
 Test if a given column and row are on the chessboard. More...
 

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.

References cwmm::ChessboardWidget::colrow2xy(), cwmm::ChessboardWidget::get_active_turn_indicator(), cwmm::ChessboardWidget::get_square(), cwmm::ChessboardWidget::is_inside_board(), cwmm::ChessboardWidget::set_active_turn_indicator(), cwmm::ChessboardWidget::set_square(), cwmm::ChessboardWidget::x2col(), and cwmm::ChessboardWidget::y2row().

Member Function Documentation

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

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 
)
inlinevirtual

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 
)
inlinevirtual

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 
)
inlinevirtual

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.

References clipboard_paste().

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.