ChessboardWidget.cc
Go to the documentation of this file.
1 // cwchessboard -- A C++ chessboard tool set for gtkmm
2 //
3 //! @file ChessboardWidget.cc This file contains the implementation of the gtkmm class ChessboardWidget.
4 //
5 // Copyright (C) 2008, 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 USE_PCH
25 #include "sys.h"
26 #endif
27 
28 #include "ChessboardWidget.h"
29 #include "CwChessboardCodes.h"
30 
31 namespace cwmm {
32 
33 void ChessboardWidget::S_draw_turn_indicator_hook(CwChessboard* chessboard, gboolean white, gboolean on)
34 {
35  static_cast<ChessboardWidget*>(chessboard->gtkmm_widget)->draw_turn_indicator(white, on);
36 }
37 
38 void ChessboardWidget::S_draw_border_hook(CwChessboard* chessboard)
39 {
40  static_cast<ChessboardWidget*>(chessboard->gtkmm_widget)->draw_border();
41 }
42 
43 void ChessboardWidget::S_draw_hud_layer_hook(CwChessboard* chessboard, cairo_t* cr, gint sside, guint hud)
44 {
45  static_cast<ChessboardWidget*>(chessboard->gtkmm_widget)->draw_hud_layer(cr, sside, hud);
46 }
47 
48 gboolean ChessboardWidget::S_draw_hud_square_hook(CwChessboard* chessboard, cairo_t* cr, gint col, gint row, gint sside, guint hud)
49 {
50  return static_cast<ChessboardWidget*>(chessboard->gtkmm_widget)->draw_hud_square(cr, col, row, sside, hud);
51 }
52 
53 void ChessboardWidget::S_draw_pawn_hook(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
54 {
55  static_cast<ChessboardWidget*>(chessboard->gtkmm_widget)->draw_pawn(cr, x, y, sside, white);
56 }
57 
58 void ChessboardWidget::S_draw_rook_hook(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
59 {
60  static_cast<ChessboardWidget*>(chessboard->gtkmm_widget)->draw_rook(cr, x, y, sside, white);
61 }
62 
63 void ChessboardWidget::S_draw_knight_hook(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
64 {
65  static_cast<ChessboardWidget*>(chessboard->gtkmm_widget)->draw_knight(cr, x, y, sside, white);
66 }
67 
68 void ChessboardWidget::S_draw_bishop_hook(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
69 {
70  static_cast<ChessboardWidget*>(chessboard->gtkmm_widget)->draw_bishop(cr, x, y, sside, white);
71 }
72 
73 void ChessboardWidget::S_draw_queen_hook(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
74 {
75  static_cast<ChessboardWidget*>(chessboard->gtkmm_widget)->draw_queen(cr, x, y, sside, white);
76 }
77 
78 void ChessboardWidget::S_draw_king_hook(CwChessboard* chessboard, cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
79 {
80  static_cast<ChessboardWidget*>(chessboard->gtkmm_widget)->draw_king(cr, x, y, sside, white);
81 }
82 
83 void ChessboardWidget::S_on_cursor_left_chessboard_hook(CwChessboard* chessboard, gint prev_col, gint prev_row)
84 {
85  static_cast<ChessboardWidget*>(chessboard->gtkmm_widget)->on_cursor_left_chessboard(prev_col, prev_row);
86 }
87 
88 void ChessboardWidget::S_on_cursor_entered_square_hook(CwChessboard* chessboard, gint prev_col, gint prev_row, gint col, gint row)
89 {
90  static_cast<ChessboardWidget*>(chessboard->gtkmm_widget)->on_cursor_entered_square(prev_col, prev_row, col, row);
91 }
92 
93 ChessboardWidget::ChessboardWidget() : Gtk::DrawingArea(&M_chessboard->parent)
94 {
95  // Initialize casting pointer.
96  M_chessboard->gtkmm_widget = static_cast<void*>(this);
97 
98  // Connect the events to our virtual functions.
99  signal_button_press_event().connect(sigc::mem_fun(*this,& ChessboardWidget::on_button_press_event));
100  signal_button_release_event().connect(sigc::mem_fun(*this,& ChessboardWidget::on_button_release_event));
101  CW_CHESSBOARD_GET_CLASS(M_chessboard)->draw_turn_indicator = S_draw_turn_indicator_hook;
102  CW_CHESSBOARD_GET_CLASS(M_chessboard)->cursor_left_chessboard = S_on_cursor_left_chessboard_hook;
103  CW_CHESSBOARD_GET_CLASS(M_chessboard)->cursor_entered_square = S_on_cursor_entered_square_hook;
104  CW_CHESSBOARD_GET_CLASS(M_chessboard)->draw_border = S_draw_border_hook;
105  CW_CHESSBOARD_GET_CLASS(M_chessboard)->draw_hud_layer = S_draw_hud_layer_hook;
106  CW_CHESSBOARD_GET_CLASS(M_chessboard)->draw_hud_square = S_draw_hud_square_hook;
107  CW_CHESSBOARD_GET_CLASS(M_chessboard)->draw_piece[(::white_pawn >> 1) - 1] = S_draw_pawn_hook;
108  CW_CHESSBOARD_GET_CLASS(M_chessboard)->draw_piece[(::white_rook >> 1) - 1] = S_draw_rook_hook;
109  CW_CHESSBOARD_GET_CLASS(M_chessboard)->draw_piece[(::white_knight >> 1) - 1] = S_draw_knight_hook;
110  CW_CHESSBOARD_GET_CLASS(M_chessboard)->draw_piece[(::white_bishop >> 1) - 1] = S_draw_bishop_hook;
111  CW_CHESSBOARD_GET_CLASS(M_chessboard)->draw_piece[(::white_queen >> 1) - 1] = S_draw_queen_hook;
112  CW_CHESSBOARD_GET_CLASS(M_chessboard)->draw_piece[(::white_king >> 1) - 1] = S_draw_king_hook;
113 }
114 
116 {
117 }
118 
119 } // namespace cwmm
virtual void draw_knight(cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
Called to draw a knight.
CwChessboardCode const white_bishop
virtual ~ChessboardWidget()
Destructor.
virtual void draw_border(void)
Draw the border around the chessboard.
ColorData const white
A constant representing the color white.
Definition: Color.h:55
virtual void draw_turn_indicator(gboolean white, gboolean on)
Draw the indicator that indicates whose turn it is.
virtual void draw_pawn(cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
Called to draw a pawn.
A gtkmm chessboard widget.
CwChessboardCode const white_pawn
virtual void draw_bishop(cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
Called to draw a bishop.
A GTK+ chessboard widget.
Definition: CwChessboard.h:101
CwChessboardCode const white_queen
gint sside(void) const
The side of a square in pixels.
virtual void draw_queen(cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
Called to draw a queen.
virtual gboolean draw_hud_square(cairo_t* cr, gint col, gint row, gint sside, guint hud)
Draw a single HUD square at col, row.
CwChessboardCode const white_rook
ChessboardWidget(void)
Create a ChessboardWidget object.
virtual bool on_button_press_event(GdkEventButton* event)
Called when the mouse button is pressed while on the chessboard widget.
This file contains the declaration of the gtkmm class ChessboardWidget.
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.
virtual bool on_button_release_event(GdkEventButton* event)
Called when the mouse button is released again.
CwChessboardCode const white_knight
A namespace for all gtkmm related objects.
virtual void draw_rook(cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
Called to draw a rook.
CwChessboardCode const white_king
virtual void draw_king(cairo_t* cr, gdouble x, gdouble y, gdouble sside, gboolean white)
Called to draw a king.
virtual void draw_hud_layer(cairo_t* cr, gint sside, guint hud)
Draw the HUD layer.
This file contains the definitions of the CwChessboardCode constants.
virtual void on_cursor_left_chessboard(gint prev_col, gint prev_row)
Called when the mouse pointer left the chessboard.

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