Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef CHESSPOSITIONWIDGET_H
00025 #define CHESSPOSITIONWIDGET_H
00026
00027 #ifndef USE_PCH
00028 #include <boost/shared_ptr.hpp>
00029 #include <gtkmm/menu.h>
00030 #include <gtkmm/uimanager.h>
00031 #include <gtkmm/iconfactory.h>
00032 #include <gtkmm/window.h>
00033 #endif
00034
00035 #include "ChessboardWidget.h"
00036 #include "ChessPosition.h"
00037 #include "Promotion.h"
00038
00039 namespace cwmm {
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 class ChessPositionWidget : protected cwchess::ChessPosition, public cwmm::ChessboardWidget {
00090 public:
00091
00092
00093
00094
00095 typedef unsigned int widget_mode_type;
00096
00097 static widget_mode_type const mode_edit_position = 0;
00098
00099 static widget_mode_type const mode_edit_game = 1;
00100
00101 static widget_mode_type const mode_disabled = 2;
00102
00103
00104 widget_mode_type get_widget_mode(void) const { return M_widget_mode; }
00105
00106 void set_widget_mode(widget_mode_type widget_mode) { M_widget_mode = widget_mode; }
00107
00108
00109
00110 private:
00111
00112 widget_mode_type M_widget_mode;
00113
00114 sigc::signal<void, cwchess::Index const&, cwchess::ChessPosition const&> M_signal_picked_up;
00115
00116 sigc::signal<void, gint, gint, cwchess::ChessPosition const&> M_signal_dropped;
00117
00118 gint M_floating_piece_handle;
00119
00120 Glib::ustring M_clipboard_content;
00121
00122 bool M_trying_primary;
00123
00124
00125
00126
00127
00128 cwchess::Index M_move_from;
00129
00130 Glib::RefPtr<cwchess::Promotion> M_promotion;
00131
00132 sigc::signal<void, cwchess::Move const&, cwchess::ChessPosition const&, cwchess::ChessPosition const&> M_signal_moved;
00133
00134 sigc::signal<void, cwchess::Move const&, cwchess::ChessPosition const&> M_signal_illegal;
00135
00136
00137
00138
00139
00140
00141 protected:
00142
00143 cwchess::Index M_placepiece_index;
00144
00145 Gtk::Window* M_drawable;
00146
00147 Gtk::Menu* M_MenuPopup;
00148
00149 Glib::RefPtr<Gtk::UIManager> M_refUIManager;
00150
00151 Glib::RefPtr<Gtk::ActionGroup> M_refActionGroup;
00152
00153 Glib::RefPtr<Gtk::IconFactory> M_refIconFactory;
00154
00155 Glib::RefPtr<Gtk::RadioAction> M_refToMoveWhite_action;
00156
00157 Glib::RefPtr<Gtk::RadioAction> M_refToMoveBlack_action;
00158
00159 Glib::RefPtr<Gtk::ToggleAction> M_refPieceHasMoved_action;
00160
00161 Glib::RefPtr<Gtk::ToggleAction> M_refAllowEnPassantCapture_action;
00162
00163 sigc::connection M_PieceHasMoved_connection;
00164
00165 sigc::connection M_AllowEnPassantCapture_connection;
00166
00167
00168
00169 public:
00170
00171
00172
00173
00174
00175
00176
00177
00178 ChessPositionWidget(Gtk::Window* drawable, Glib::RefPtr<cwchess::Promotion> promotion = Glib::RefPtr<cwchess::Promotion>(new cwchess::Promotion)) :
00179 M_floating_piece_handle(-1), M_widget_mode(mode_edit_position), M_promotion(promotion), M_MenuPopup(NULL), M_drawable(drawable), M_trying_primary(false)
00180 {
00181
00182 drawable->signal_realize().connect(sigc::mem_fun(this,& ChessPositionWidget::initialize_menus));
00183 }
00184
00185
00186
00187 private:
00188 void initialize_menus(void);
00189 bool popup_menu(GdkEventButton* event, int col, int row);
00190 void popup_deactivated(void);
00191 void update_paste_status(void);
00192
00193 protected:
00194 virtual void on_menu_placepiece_black_pawn(void);
00195 virtual void on_menu_placepiece_black_rook(void);
00196 virtual void on_menu_placepiece_black_knight(void);
00197 virtual void on_menu_placepiece_black_bishop(void);
00198 virtual void on_menu_placepiece_black_queen(void);
00199 virtual void on_menu_placepiece_black_king(void);
00200 virtual void on_menu_placepiece_white_pawn(void);
00201 virtual void on_menu_placepiece_white_rook(void);
00202 virtual void on_menu_placepiece_white_knight(void);
00203 virtual void on_menu_placepiece_white_bishop(void);
00204 virtual void on_menu_placepiece_white_queen(void);
00205 virtual void on_menu_placepiece_white_king(void);
00206 virtual void on_menu_placepiece_nothing(void);
00207 virtual void on_menu_allow_en_passant_capture(void);
00208 virtual void on_menu_piece_has_moved(void);
00209 virtual void on_menu_copy_FEN(void);
00210 virtual void on_menu_paste_FEN(void);
00211 virtual void on_menu_swap_colors(void);
00212 virtual void on_menu_initial_position(void);
00213 virtual void on_menu_clear_board(void);
00214 virtual void on_menu_to_move_white(void);
00215 virtual void on_menu_to_move_black(void);
00216 virtual void on_clipboard_get(Gtk::SelectionData& selection_data, guint info);
00217 virtual void on_clipboard_clear(void);
00218 virtual void on_clipboard_received(Glib::ustring const& text);
00219 virtual void on_clipboard_received_targets(Glib::StringArrayHandle const& targets_array);
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230 protected:
00231 using ChessboardWidget::set_square;
00232 using ChessboardWidget::get_square;
00233 using ChessboardWidget::set_active_turn_indicator;
00234 using ChessboardWidget::get_active_turn_indicator;
00235
00236
00237
00238 public:
00239 using ChessboardWidget::trackable;
00240 using ChessboardWidget::ColorHandle;
00241 using ChessboardWidget::code_t;
00242 using ChessboardWidget::colrow2xy;
00243 using ChessboardWidget::x2col;
00244 using ChessboardWidget::y2row;
00245 using ChessboardWidget::is_inside_board;
00246
00247
00248
00249
00250
00251
00252
00253
00254 using ChessPosition::set_half_move_clock;
00255 using ChessPosition::set_full_move_number;
00256 using ChessPosition::set_has_moved;
00257 using ChessPosition::clear_has_moved;
00258
00259
00260 void clear(void) { ChessPosition::clear(); sync(); }
00261
00262 void initial_position(void) { ChessPosition::initial_position(); sync(); }
00263
00264 bool skip_move(void) { bool result = ChessPosition::skip_move(); set_active_turn_indicator(to_move().is_white()); return result; }
00265
00266 void to_move(cwchess::Color const& color) { ChessPosition::to_move(color); set_active_turn_indicator(to_move().is_white()); }
00267
00268 bool set_en_passant(cwchess::Index const& index) { ChessPosition::set_en_passant(index); set_active_turn_indicator(to_move().is_white()); }
00269
00270 void swap_colors(void) { ChessPosition::swap_colors(); sync(); }
00271
00272 bool place(cwchess::Code const& code, cwchess::Index const& index) { if (ChessPosition::place(code, index)) set_square(index.col(), index.row(), code); }
00273
00274 bool load_FEN(std::string const& FEN);
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285 public:
00286 using ChessPosition::piece_at;
00287 using ChessPosition::to_move;
00288 using ChessPosition::half_move_clock;
00289 using ChessPosition::full_move_number;
00290 using ChessPosition::castle_flags;
00291 using ChessPosition::en_passant;
00292 using ChessPosition::all;
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 public:
00304 using ChessPosition::FEN;
00305 using ChessPosition::candidates_table_offset;
00306 using ChessPosition::candidates;
00307 using ChessPosition::reachables;
00308 using ChessPosition::defendables;
00309 using ChessPosition::index_of_king;
00310 using ChessPosition::check;
00311 using ChessPosition::double_check;
00312 using ChessPosition::moves;
00313 using ChessPosition::legal;
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 public:
00325 using ChessPosition::piece_begin;
00326 using ChessPosition::piece_end;
00327 using ChessPosition::move_begin;
00328 using ChessPosition::move_end;
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 bool execute(cwchess::Move const& move);
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351 public:
00352 using ChessboardWidget::sside;
00353 using ChessboardWidget::top_left_a1_x;
00354 using ChessboardWidget::top_left_a1_y;
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365 public:
00366 using ChessboardWidget::set_draw_border;
00367 using ChessboardWidget::get_draw_border;
00368 using ChessboardWidget::set_draw_turn_indicators;
00369 using ChessboardWidget::get_draw_turn_indicators;
00370 using ChessboardWidget::set_flip_board;
00371 using ChessboardWidget::get_flip_board;
00372 using ChessboardWidget::set_calc_board_border_width ;
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383 public:
00384 using ChessboardWidget::set_dark_square_color;
00385 using ChessboardWidget::set_light_square_color;
00386 using ChessboardWidget::set_border_color;
00387 using ChessboardWidget::set_white_fill_color;
00388 using ChessboardWidget::set_white_line_color;
00389 using ChessboardWidget::set_black_fill_color;
00390 using ChessboardWidget::set_black_line_color;
00391 using ChessboardWidget::get_dark_square_color;
00392 using ChessboardWidget::get_light_square_color;
00393 using ChessboardWidget::get_border_color;
00394 using ChessboardWidget::get_white_fill_color;
00395 using ChessboardWidget::get_white_line_color;
00396 using ChessboardWidget::get_black_fill_color;
00397 using ChessboardWidget::get_black_line_color;
00398 using ChessboardWidget::allocate_color_handle_rgb;
00399 using ChessboardWidget::allocate_color_handle;
00400 using ChessboardWidget::free_color_handle;
00401 using ChessboardWidget::set_background_color;
00402 using ChessboardWidget::get_background_color;
00403 using ChessboardWidget::set_background_colors;
00404 using ChessboardWidget::get_background_colors;
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415 public:
00416 using ChessboardWidget::add_floating_piece;
00417 using ChessboardWidget::move_floating_piece;
00418 using ChessboardWidget::remove_floating_piece;
00419 using ChessboardWidget::get_floating_piece;
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430 public:
00431 using ChessboardWidget::enable_hud_layer;
00432 using ChessboardWidget::disable_hud_layer;
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443 public:
00444 using ChessboardWidget::set_marker_color;
00445 using ChessboardWidget::get_marker_color;
00446 using ChessboardWidget::set_marker_thickness;
00447 using ChessboardWidget::get_marker_thickness;
00448 using ChessboardWidget::set_marker_level;
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459 public:
00460 using ChessboardWidget::show_cursor;
00461 using ChessboardWidget::hide_cursor ;
00462 using ChessboardWidget::set_cursor_thickness;
00463 using ChessboardWidget::get_cursor_thickness;
00464 using ChessboardWidget::set_cursor_color;
00465 using ChessboardWidget::get_cursor_color;
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476 public:
00477 using ChessboardWidget::add_arrow;
00478 using ChessboardWidget::remove_arrow;
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489 void set_position(cwchess::ChessPosition const& chess_position) {* static_cast<cwchess::ChessPosition*>(this) = chess_position; sync(); }
00490
00491
00492 void clipboard_paste(void);
00493
00494
00495
00496
00497
00498
00499
00500 ChessPosition const& get_position(void) const { return* this; }
00501
00502
00503 void clipboard_copy(void) const;
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534 virtual bool on_button_press(gint col, gint row, GdkEventButton const* event) { return false; }
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552 virtual bool on_button_release(gint col, gint row, GdkEventButton const* event) { return false; }
00553
00554
00555
00556
00557
00558 virtual void on_cursor_left_chessboard(gint prev_col, gint prev_row) { }
00559
00560
00561
00562
00563
00564 virtual void on_cursor_entered_square(gint prev_col, gint prev_row, gint col, gint row) { }
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582 sigc::signal<void, cwchess::Index const&, cwchess::ChessPosition const&>& signal_picked_up(void) { return M_signal_picked_up; }
00583
00584
00585
00586
00587
00588
00589 sigc::signal<void, gint, gint, cwchess::ChessPosition const&>& signal_dropped(void) { return M_signal_dropped; }
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604 sigc::signal<void, cwchess::Move const&, cwchess::ChessPosition const&, cwchess::ChessPosition const&>& signal_moved(void) { return M_signal_moved; }
00605
00606
00607
00608
00609
00610
00611
00612
00613 sigc::signal<void, cwchess::Move const&, cwchess::ChessPosition const&>& signal_illegal(void) { return M_signal_illegal; }
00614
00615
00616
00617 protected_notdocumented:
00618 virtual bool on_button_press_event(GdkEventButton* event);
00619 virtual bool on_button_release_event(GdkEventButton* event);
00620
00621 private:
00622 void sync(void);
00623 };
00624
00625 }
00626
00627 #endif // CHESSPOSITIONWIDGET_H