Revision: 50
http://chessdrills.svn.sourceforge.net/chessdrills/?rev=50&view=rev
Author: phantomfive
Date: 2007-08-09 23:24:04 -0700 (Thu, 09 Aug 2007)
Log Message:
-----------
SquareWasSelected() now works.
Modified Paths:
--------------
drills/ExampleDrill.cpp
drills/ExampleDrill.h
gui/GuiControl.h
gui/MainWindow.cpp
gui/MainWindow.h
Modified: drills/ExampleDrill.cpp
===================================================================
--- drills/ExampleDrill.cpp 2007-08-07 09:34:03 UTC (rev 49)
+++ drills/ExampleDrill.cpp 2007-08-10 06:24:04 UTC (rev 50)
@@ -94,6 +94,12 @@
}
}
+void ExampleDrill::SquareWasSelected( const ChessSquare &location,
+ const ChessPiece &piece ){
+ printf("got square selected, (%d,%d), piece %d\n",location.col,
+ location.row, piece.type );
+}
+
//-------------------------------------------------------------------------
// Private methods
//-------------------------------------------------------------------------
Modified: drills/ExampleDrill.h
===================================================================
--- drills/ExampleDrill.h 2007-08-07 09:34:03 UTC (rev 49)
+++ drills/ExampleDrill.h 2007-08-10 06:24:04 UTC (rev 50)
@@ -26,7 +26,8 @@
const ChessSquare &to,
const ChessPiece &captured);
-
+void ExampleDrill::SquareWasSelected( const ChessSquare &location,
+ const ChessPiece &piece );
private:
ChessSquare myPawn; //location of computer's pawn
Modified: gui/GuiControl.h
===================================================================
--- gui/GuiControl.h 2007-08-07 09:34:03 UTC (rev 49)
+++ gui/GuiControl.h 2007-08-10 06:24:04 UTC (rev 50)
@@ -57,6 +57,8 @@
//--------------------------------------------------------------
//Methods called by the GUI
//--------------------------------------------------------------
+ //Indicate when a square is selected
+ void SquareWasSelected( int &row, int &col );
//Returns a list of the drills that are available. These names
//should appear in a menu
const char** GetDrillList();
Modified: gui/MainWindow.cpp
===================================================================
--- gui/MainWindow.cpp 2007-08-07 09:34:03 UTC (rev 49)
+++ gui/MainWindow.cpp 2007-08-10 06:24:04 UTC (rev 50)
@@ -20,6 +20,7 @@
BEGIN_EVENT_TABLE(MainWindow, wxFrame)
EVT_PAINT(MainWindow::Redraw)
EVT_LEFT_DOWN(MainWindow::OnMouseClick)
+EVT_LEFT_UP(MainWindow::OnMouseUp)
EVT_MENU(ID_Quit, MainWindow::OnQuit)
EVT_MENU(ID_SelectDrill1, MainWindow::OnSelectDrill)
EVT_MENU(ID_SelectDrill2, MainWindow::OnSelectDrill)
@@ -149,9 +150,9 @@
//draw that piece
if( img!= NULL ){
if(boardIsFlipped)
- dc.DrawBitmap(*img, (8-j)*SQUARE_HEIGHT, (8-i*SQUARE_WIDTH), true);
+ dc.DrawBitmap(*img, j*SQUARE_HEIGHT, i*SQUARE_WIDTH,true);
else
- dc.DrawBitmap(*img, j*SQUARE_HEIGHT, i*SQUARE_WIDTH,true);
+ dc.DrawBitmap(*img, (j)*SQUARE_HEIGHT, (7-i)*SQUARE_WIDTH, true);
}
}
}
@@ -175,8 +176,7 @@
//-----------------------------------------------------------------------
// Mouse functions
//-----------------------------------------------------------------------
-void MainWindow::OnMouseClick( wxMouseEvent& event )
-{
+void MainWindow::OnMouseClick( wxMouseEvent& event ){
int row, col;
bool rv;
printf("Got a mouse down event!!\n");
@@ -185,7 +185,16 @@
printf("square is (%d,%d) it is %s the board\n",col,row,
(rv)?"on":"not on");
}
-
+
+void MainWindow::OnMouseUp( wxMouseEvent& event ){
+ int row, col;
+ bool rv;
+ rv = GetSquareFromPoint(event.m_x, event.m_y, row, col );
+ if( rv ){
+ ctl.SquareWasSelected( row, col );
+ }
+}
+
bool MainWindow::GetSquareFromPoint(int x, int y, int &row, int &col){
if(boardIsFlipped){
row = y/SQUARE_HEIGHT;
@@ -201,3 +210,4 @@
return false;
}
+
Modified: gui/MainWindow.h
===================================================================
--- gui/MainWindow.h 2007-08-07 09:34:03 UTC (rev 49)
+++ gui/MainWindow.h 2007-08-10 06:24:04 UTC (rev 50)
@@ -26,6 +26,7 @@
void Redraw(wxPaintEvent &event);
void OnSelectDrill(wxCommandEvent& event);
void OnMouseClick( wxMouseEvent& event );
+ void OnMouseUp( wxMouseEvent& event );
DECLARE_EVENT_TABLE()
//PUBLIC METHODS
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|