From: <pha...@us...> - 2007-08-07 09:34:38
|
Revision: 49 http://chessdrills.svn.sourceforge.net/chessdrills/?rev=49&view=rev Author: phantomfive Date: 2007-08-07 02:34:03 -0700 (Tue, 07 Aug 2007) Log Message: ----------- made square calculation a bit more sophisticated (it now checks if the click was on the board or not Modified Paths: -------------- gui/MainWindow.cpp gui/MainWindow.h Modified: gui/MainWindow.cpp =================================================================== --- gui/MainWindow.cpp 2007-08-07 09:28:51 UTC (rev 48) +++ gui/MainWindow.cpp 2007-08-07 09:34:03 UTC (rev 49) @@ -178,13 +178,15 @@ void MainWindow::OnMouseClick( wxMouseEvent& event ) { int row, col; + bool rv; printf("Got a mouse down event!!\n"); printf("located at (%d,%d)\n",event.m_x, event.m_y); - GetSquareFromPoint(event.m_x,event.m_y,row,col); - printf("square is (%d,%d)\n",col,row); + rv = GetSquareFromPoint(event.m_x,event.m_y,row,col); + printf("square is (%d,%d) it is %s the board\n",col,row, + (rv)?"on":"not on"); } -void MainWindow::GetSquareFromPoint(int x, int y, int &row, int &col){ +bool MainWindow::GetSquareFromPoint(int x, int y, int &row, int &col){ if(boardIsFlipped){ row = y/SQUARE_HEIGHT; col = x/SQUARE_WIDTH; @@ -193,5 +195,9 @@ row = 7 - y/SQUARE_HEIGHT; col = x/SQUARE_WIDTH; } + //make sure it's on the board + if( row <=7 && row >=0 && col <=7 && col>=0 ) + return true; + return false; } Modified: gui/MainWindow.h =================================================================== --- gui/MainWindow.h 2007-08-07 09:28:51 UTC (rev 48) +++ gui/MainWindow.h 2007-08-07 09:34:03 UTC (rev 49) @@ -47,7 +47,8 @@ private: int boardWidth; //in pixels void DrawBoard(wxDC &dc, const ChessBoard *board); - void GetSquareFromPoint(int x, int y, int &row, int &col); + //returns true if the square is on the board, false otherwise + bool GetSquareFromPoint(int x, int y, int &row, int &col); //the Gui Control object. Maybe it should be called something //else, since really the GUI controls everything else. Maybe This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |