You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
(14) |
Sep
|
Oct
|
Nov
|
Dec
|
---|
From: <pha...@us...> - 2007-08-26 11:08:23
|
Revision: 58 http://chessdrills.svn.sourceforge.net/chessdrills/?rev=58&view=rev Author: phantomfive Date: 2007-08-24 19:25:26 -0700 (Fri, 24 Aug 2007) Log Message: ----------- prettier images Modified Paths: -------------- images/blackBishop.gif images/blackQueen.gif images/whiteBishop.gif images/whiteKing.gif images/whiteKnight.gif Modified: images/blackBishop.gif =================================================================== (Binary files differ) Modified: images/blackQueen.gif =================================================================== (Binary files differ) Modified: images/whiteBishop.gif =================================================================== (Binary files differ) Modified: images/whiteKing.gif =================================================================== (Binary files differ) Modified: images/whiteKnight.gif =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pha...@us...> - 2007-08-23 01:25:35
|
Revision: 57 http://chessdrills.svn.sourceforge.net/chessdrills/?rev=57&view=rev Author: phantomfive Date: 2007-08-22 18:25:29 -0700 (Wed, 22 Aug 2007) Log Message: ----------- made sure that a reset() also clears the hilighted squares Modified Paths: -------------- base/ChessBoard.cpp Modified: base/ChessBoard.cpp =================================================================== --- base/ChessBoard.cpp 2007-08-22 06:01:20 UTC (rev 56) +++ base/ChessBoard.cpp 2007-08-23 01:25:29 UTC (rev 57) @@ -80,7 +80,7 @@ board[i][j].col = (ChessColumn)i; board[i][j].color = (((i%2) + (j%2))%2)?CLR_BLACK:CLR_WHITE; board[i][j].piece.type = CP_NOPIECE; - + board[i][j].type = SQR_NORMAL; } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pha...@us...> - 2007-08-22 06:01:21
|
Revision: 56 http://chessdrills.svn.sourceforge.net/chessdrills/?rev=56&view=rev Author: phantomfive Date: 2007-08-21 23:01:20 -0700 (Tue, 21 Aug 2007) Log Message: ----------- some better images for a few of the pieces Modified Paths: -------------- images/blackKing.gif images/blackRook.gif images/whiteQueen.gif images/whiteRook.gif Modified: images/blackKing.gif =================================================================== (Binary files differ) Modified: images/blackRook.gif =================================================================== (Binary files differ) Modified: images/whiteQueen.gif =================================================================== (Binary files differ) Modified: images/whiteRook.gif =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pha...@us...> - 2007-08-21 16:13:54
|
Revision: 55 http://chessdrills.svn.sourceforge.net/chessdrills/?rev=55&view=rev Author: phantomfive Date: 2007-08-21 09:13:52 -0700 (Tue, 21 Aug 2007) Log Message: ----------- These don't hurt my eyes so much Modified Paths: -------------- images/blackPawn.gif images/whitePawn.gif Modified: images/blackPawn.gif =================================================================== (Binary files differ) Modified: images/whitePawn.gif =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pha...@us...> - 2007-08-21 07:19:14
|
Revision: 54 http://chessdrills.svn.sourceforge.net/chessdrills/?rev=54&view=rev Author: phantomfive Date: 2007-08-21 00:19:12 -0700 (Tue, 21 Aug 2007) Log Message: ----------- added square hilighting Modified Paths: -------------- base/ChessDrill.cpp base/ChessDrill.h base/ChessTypes.h drills/ExampleDrill.cpp drills/ExampleDrill.h gui/GuiControl.cpp gui/GuiControl.h gui/MainWindow.cpp gui/MainWindow.h Modified: base/ChessDrill.cpp =================================================================== --- base/ChessDrill.cpp 2007-08-21 06:30:38 UTC (rev 53) +++ base/ChessDrill.cpp 2007-08-21 07:19:12 UTC (rev 54) @@ -68,7 +68,10 @@ ChessPiece &captured ){ gui->MovePiece(from, to, captured); } - +void ChessDrill::SetSquareHilight( const ChessColumn &col, const ChessRow &row, + const ChessSquareType type ){ + gui->SetSquareHilight(col, row, type); +} void ChessDrill::SetSquare(const ChessColumn &col, const ChessRow &row, const ChessSquare &square){ gui->SetSquare(col, row, square); Modified: base/ChessDrill.h =================================================================== --- base/ChessDrill.h 2007-08-21 06:30:38 UTC (rev 53) +++ base/ChessDrill.h 2007-08-21 07:19:12 UTC (rev 54) @@ -101,6 +101,14 @@ void MovePiece(const ChessSquare &from, const ChessSquare &to, ChessPiece &captured ); + //This allows you to set the hilighting of a square + //PARAM col - the column of the square + //PARAM row - the row of the square + //PARAM type - The style to use to hilight the square. It can be either + // SQR_NORMAL, SQR_HILIGHT1, SQR_HILIGHT2, or QR_HILIGHT3 + void SetSquareHilight( const ChessColumn &col, const ChessRow &row, + const ChessSquareType type ); + //This allows you to set up a square any way you like, and erase what was //there before. //PARAM col - the column of the square. Modified: base/ChessTypes.h =================================================================== --- base/ChessTypes.h 2007-08-21 06:30:38 UTC (rev 53) +++ base/ChessTypes.h 2007-08-21 07:19:12 UTC (rev 54) @@ -46,8 +46,9 @@ enum ChessSquareType{ SQR_DEFAULT, //set this if you don't care what type it is SQR_NORMAL, //set this to un-hilight the square - SQR_HILIGHT, - SQR_MARKED + SQR_HILIGHT1, + SQR_HILIGHT2, + SQR_HILIGHT3 }; enum ChessColor{ Modified: drills/ExampleDrill.cpp =================================================================== --- drills/ExampleDrill.cpp 2007-08-21 06:30:38 UTC (rev 53) +++ drills/ExampleDrill.cpp 2007-08-21 07:19:12 UTC (rev 54) @@ -19,7 +19,7 @@ bool ExampleDrill::Start(){ ChessSquare tempSquare; - + hilight = 0; //first clear the board (not necessary, but just in case) ClearBoard(); @@ -98,6 +98,7 @@ const ChessPiece &piece ){ printf("got square selected, (%d,%d), piece %d\n",location.col, location.row, piece.type ); + SetSquareHilight( location.col, location.row, (ChessSquareType)4); } bool ExampleDrill::ShouldAllowPiecePickup( const ChessPiece &piece, Modified: drills/ExampleDrill.h =================================================================== --- drills/ExampleDrill.h 2007-08-21 06:30:38 UTC (rev 53) +++ drills/ExampleDrill.h 2007-08-21 07:19:12 UTC (rev 54) @@ -36,7 +36,7 @@ ChessSquare myPawn; //location of computer's pawn ChessSquare theirPawn; //location of computer's pawn - + int hilight; bool MoveIsValid(const ChessSquare &from, const ChessSquare &to); }; Modified: gui/GuiControl.cpp =================================================================== --- gui/GuiControl.cpp 2007-08-21 06:30:38 UTC (rev 53) +++ gui/GuiControl.cpp 2007-08-21 07:19:12 UTC (rev 54) @@ -34,7 +34,12 @@ ChessPiece &captured ){ board.MovePiece(from, to, captured); } - +void GuiControl::SetSquareHilight( const ChessColumn &col, const ChessRow &row, + const ChessSquareType type ){ + ChessSquare s = *(board.GetSquare(col, row)); + s.type = type; + board.SetSquare(col, row, s); +} void GuiControl::SetSquare(const ChessColumn &col, const ChessRow &row, const ChessSquare &square){ board.SetSquare(col, row, square); Modified: gui/GuiControl.h =================================================================== --- gui/GuiControl.h 2007-08-21 06:30:38 UTC (rev 53) +++ gui/GuiControl.h 2007-08-21 07:19:12 UTC (rev 54) @@ -35,6 +35,9 @@ void MovePiece(const ChessSquare &from, const ChessSquare &to, ChessPiece &captured ); + void SetSquareHilight( const ChessColumn &col, const ChessRow &row, + const ChessSquareType type ); + void SetSquare(const ChessColumn &col, const ChessRow &row, const ChessSquare &square); Modified: gui/MainWindow.cpp =================================================================== --- gui/MainWindow.cpp 2007-08-21 06:30:38 UTC (rev 53) +++ gui/MainWindow.cpp 2007-08-21 07:19:12 UTC (rev 54) @@ -57,7 +57,10 @@ !blackKing.LoadFile("images/blackKing.gif",wxBITMAP_TYPE_GIF) || !whiteKing.LoadFile("images/whiteKing.gif",wxBITMAP_TYPE_GIF) || !blackQueen.LoadFile("images/blackQueen.gif",wxBITMAP_TYPE_GIF) || - !whiteQueen.LoadFile("images/whiteQueen.gif",wxBITMAP_TYPE_GIF) ) + !whiteQueen.LoadFile("images/whiteQueen.gif",wxBITMAP_TYPE_GIF) || + !hilight1.LoadFile("images/hilight1.gif", wxBITMAP_TYPE_GIF) || + !hilight2.LoadFile("images/hilight2.gif", wxBITMAP_TYPE_GIF) || + !hilight3.LoadFile("images/hilight3.gif", wxBITMAP_TYPE_GIF) ) { printf("error couldn't load images!!!\n"); exit(-1); @@ -132,18 +135,44 @@ if( NULL != board ){ for(int i=0;i<8;i++){ for(int j=0;j<8;j++){ + const ChessSquare *square = board->GetSquare((ChessColumn)j, + (ChessRow)i); + const ChessPiece *piece = board->GetPiece((ChessColumn)j,(ChessRow)i); + + //calculate the coordinates of the square + int x, y; + if( boardIsFlipped ){ + y = j*SQUARE_HEIGHT; + x = i*SQUARE_WIDTH; + } + else{ + y = j*SQUARE_HEIGHT; + x = (7-i)*SQUARE_WIDTH; + } + + //draw the hilighted squares + if( square->type == SQR_HILIGHT1 ){ + dc.DrawBitmap(hilight1, y, x, true); + } + else if( square->type == SQR_HILIGHT2 ){ + dc.DrawBitmap(hilight2, y, x, true); + } + else if( square->type == SQR_HILIGHT3 ){ + dc.DrawBitmap(hilight3, y, x, true); + } + + //if the piece is dragging don't draw it on the square it was on if( dragging && j==(int)dragStartCol && i==(int)dragStartRow ){ continue; } - const ChessPiece *piece = board->GetPiece((ChessColumn)j,(ChessRow)i); + //draw the piece img = GetImageForPiece( piece ); - //draw that piece if( img!= NULL ){ if(boardIsFlipped) - dc.DrawBitmap(*img, j*SQUARE_HEIGHT, i*SQUARE_WIDTH,true); + dc.DrawBitmap(*img, y, x,true); else - dc.DrawBitmap(*img, (j)*SQUARE_HEIGHT, (7-i)*SQUARE_WIDTH, true); + dc.DrawBitmap(*img, y, x, true); } } } @@ -271,9 +300,9 @@ } } dragging = false; - Refresh( false ); - Update(); } + Refresh( false ); + Update(); } void MainWindow::OnMouseMove( wxMouseEvent& event ){ Modified: gui/MainWindow.h =================================================================== --- gui/MainWindow.h 2007-08-21 06:30:38 UTC (rev 53) +++ gui/MainWindow.h 2007-08-21 07:19:12 UTC (rev 54) @@ -68,7 +68,10 @@ blackKnight, whiteKnight, blackBishop, whiteBishop, blackKing, whiteKing, - blackQueen, whiteQueen; + blackQueen, whiteQueen, + hilight1, hilight2, + hilight3; + //returns NULL if there is no image wxBitmap *GetImageForPiece( const ChessPiece *piece ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pha...@us...> - 2007-08-21 06:30:40
|
Revision: 53 http://chessdrills.svn.sourceforge.net/chessdrills/?rev=53&view=rev Author: phantomfive Date: 2007-08-20 23:30:38 -0700 (Mon, 20 Aug 2007) Log Message: ----------- images for hilighting squares Added Paths: ----------- images/hilight1.gif images/hilight2.gif images/hilight3.gif Added: images/hilight1.gif =================================================================== (Binary files differ) Property changes on: images/hilight1.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: images/hilight2.gif =================================================================== (Binary files differ) Property changes on: images/hilight2.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: images/hilight3.gif =================================================================== (Binary files differ) Property changes on: images/hilight3.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pha...@us...> - 2007-08-20 07:02:42
|
Revision: 52 http://chessdrills.svn.sourceforge.net/chessdrills/?rev=52&view=rev Author: phantomfive Date: 2007-08-20 00:02:31 -0700 (Mon, 20 Aug 2007) Log Message: ----------- The following functions of ChessDrill.h are now functional: ShouldAllowPiecePickup(), PieceWasPickedUp(), ShouldAllowPiecePlacement(), PieceWasPlaced(), SquareWasSelected() in addition to the ones that were already working Modified Paths: -------------- base/ChessDrill.h base/Main.cpp drills/ExampleDrill.cpp drills/ExampleDrill.h gui/GuiControl.cpp gui/GuiControl.h gui/MainWindow.cpp gui/MainWindow.h Modified: base/ChessDrill.h =================================================================== --- base/ChessDrill.h 2007-08-16 06:54:31 UTC (rev 51) +++ base/ChessDrill.h 2007-08-20 07:02:31 UTC (rev 52) @@ -153,10 +153,11 @@ // void SetTimer( (***), unsigned int milliseconds, void *data); //Enables or disables the board. The default state is enabled. - //PARAM enable - if false, all user input is ignored + //PARAM enable - if false, all user input is ignored so you will have to set + // a timer if you want to do anything else void Enable(bool enable); -//Pay o attention to the lines below this comment +//Pay no attention to the lines below this comment void SetGuiControl( GuiControl *gui ); private: GuiControl *gui; Modified: base/Main.cpp =================================================================== --- base/Main.cpp 2007-08-16 06:54:31 UTC (rev 51) +++ base/Main.cpp 2007-08-20 07:02:31 UTC (rev 52) @@ -14,14 +14,9 @@ bool Main::OnInit(){ //create the main window - printf("about to create a new window\n"); MainWindow *win = new MainWindow( "Chess Drills", wxPoint(50,50), wxSize(640,640) ); - printf("about to show window\n"); - win->Show(TRUE); - printf("about to set top\n"); SetTopWindow(win); - printf("returning true\n"); return TRUE; } Modified: drills/ExampleDrill.cpp =================================================================== --- drills/ExampleDrill.cpp 2007-08-16 06:54:31 UTC (rev 51) +++ drills/ExampleDrill.cpp 2007-08-20 07:02:31 UTC (rev 52) @@ -23,16 +23,16 @@ //first clear the board (not necessary, but just in case) ClearBoard(); - //put my pawn on E5 + //put my pawn on E3 myPawn.row = ROW_FIVE; - myPawn.col = COL_A; + myPawn.col = COL_E; tempSquare.piece.color = CLR_BLACK; tempSquare.piece.type = CP_PAWN; SetSquare(myPawn.col, myPawn.row, tempSquare); - //put their pawn on A3 - theirPawn.row = ROW_THREE; + //put their pawn on A5 + theirPawn.row = ROW_FIVE; theirPawn.col = COL_A; tempSquare.piece.color = CLR_WHITE; tempSquare.piece.type = CP_PAWN; @@ -100,6 +100,13 @@ location.row, piece.type ); } +bool ExampleDrill::ShouldAllowPiecePickup( const ChessPiece &piece, + const ChessSquare &from ){ + if( piece.color != CLR_WHITE ){ + return false; + } + return true; +} //------------------------------------------------------------------------- // Private methods //------------------------------------------------------------------------- @@ -110,7 +117,7 @@ if( from.col != to.col ) return false; - if( from.col != to.col - 1 ) + if( from.row != to.row - 1 ) return false; return true; Modified: drills/ExampleDrill.h =================================================================== --- drills/ExampleDrill.h 2007-08-16 06:54:31 UTC (rev 51) +++ drills/ExampleDrill.h 2007-08-20 07:02:31 UTC (rev 52) @@ -28,6 +28,10 @@ void ExampleDrill::SquareWasSelected( const ChessSquare &location, const ChessPiece &piece ); + +bool ExampleDrill::ShouldAllowPiecePickup( const ChessPiece &piece, + const ChessSquare &from ); + private: ChessSquare myPawn; //location of computer's pawn Modified: gui/GuiControl.cpp =================================================================== --- gui/GuiControl.cpp 2007-08-16 06:54:31 UTC (rev 51) +++ gui/GuiControl.cpp 2007-08-20 07:02:31 UTC (rev 52) @@ -75,6 +75,39 @@ //--------------------------------------------------------------- // Methods called by the GUI //--------------------------------------------------------------- +bool GuiControl::ShouldAllowPiecePlacement(const ChessPiece &piece, + const ChessSquare &from, + const ChessSquare &to, + const ChessPiece &captured){ + if( currentDrill != NULL ){ + return currentDrill->ShouldAllowPiecePlacement( piece, from, to, captured ); + } + return false; +} + +void GuiControl::PieceWasPlaced(const ChessPiece &piece, + const ChessSquare &from, + const ChessSquare &to, + const ChessPiece &captured){ + if( currentDrill != NULL ){ + currentDrill->PieceWasPlaced(piece, from, to, captured ); + } +} +bool GuiControl::ShouldAllowPiecePickup(const ChessPiece &piece, + const ChessSquare &from){ + if( currentDrill != NULL ){ + return currentDrill->ShouldAllowPiecePickup( piece, from ); + } + return false; +} + void GuiControl::PieceWasPickedUp(const ChessPiece &piece, + const ChessSquare &from){ + if(currentDrill != NULL ){ + currentDrill->PieceWasPickedUp( piece, from ); + } + } + + void GuiControl::SquareWasSelected( int &row, int &col ){ const ChessSquare *sqr = board.GetSquare((ChessColumn)col, (ChessRow)row); const ChessPiece *piece = &(sqr->piece); Modified: gui/GuiControl.h =================================================================== --- gui/GuiControl.h 2007-08-16 06:54:31 UTC (rev 51) +++ gui/GuiControl.h 2007-08-20 07:02:31 UTC (rev 52) @@ -52,11 +52,29 @@ void FinishDrill(); + void SetUserColor(ChessColor color); //-------------------------------------------------------------- //Methods called by the GUI //-------------------------------------------------------------- + bool ShouldAllowPiecePlacement(const ChessPiece &piece, + const ChessSquare &from, + const ChessSquare &to, + const ChessPiece &captured); + + void PieceWasPlaced(const ChessPiece &piece, + const ChessSquare &from, + const ChessSquare &to, + const ChessPiece &captured); + + bool ShouldAllowPiecePickup(const ChessPiece &piece, + const ChessSquare &from); + + void PieceWasPickedUp(const ChessPiece &piece, + const ChessSquare &from); + + //Indicate when a square is selected void SquareWasSelected( int &row, int &col ); //Returns a list of the drills that are available. These names Modified: gui/MainWindow.cpp =================================================================== --- gui/MainWindow.cpp 2007-08-16 06:54:31 UTC (rev 51) +++ gui/MainWindow.cpp 2007-08-20 07:02:31 UTC (rev 52) @@ -42,7 +42,7 @@ const wxSize &size): wxFrame((wxFrame*)NULL, -1, title, pos, size){ wxImage::AddHandler(new wxGIFHandler); - printf("starting to load file\n"); + //load the images if( !blackSquare.LoadFile("images/blackSquare.gif",wxBITMAP_TYPE_GIF) || !whiteSquare.LoadFile("images/whiteSquare.gif",wxBITMAP_TYPE_GIF) || @@ -62,9 +62,7 @@ printf("error couldn't load images!!!\n"); exit(-1); } - printf("loaded images\n"); CreateStatusBar(); - SetStatusText( "Here is our board!" ); boardIsFlipped = false; dragging = false; @@ -134,21 +132,12 @@ if( NULL != board ){ for(int i=0;i<8;i++){ for(int j=0;j<8;j++){ + if( dragging && j==(int)dragStartCol && i==(int)dragStartRow ){ + continue; + } const ChessPiece *piece = board->GetPiece((ChessColumn)j,(ChessRow)i); - ChessColor c = piece->color; - //find which piece and color - switch (piece->type){ - case CP_PAWN: img = (c==CLR_WHITE)?&whitePawn: &blackPawn;break; - case CP_ROOK: img = (c==CLR_WHITE)?&whiteRook: &blackRook;break; - case CP_KNIGHT:img = (c==CLR_WHITE)?&whiteKnight:&blackKnight;break; - case CP_BISHOP:img = (c==CLR_WHITE)?&whiteBishop:&blackBishop;break; - case CP_QUEEN: img = (c==CLR_WHITE)?&whiteQueen: &blackQueen;break; - case CP_KING: img = (c==CLR_WHITE)?&whiteKing: &blackKing;break; - - case CP_NOPIECE: - default: - img = NULL; - } + img = GetImageForPiece( piece ); + //draw that piece if( img!= NULL ){ if(boardIsFlipped) @@ -160,12 +149,35 @@ } } - //dragging stuff + //draw the piece being dragged, if necessary if( dragging ){ - dc.DrawBitmap( blackQueen, mouseX-(SQUARE_HEIGHT/2), mouseY-(SQUARE_WIDTH/2), true ); + img = GetImageForPiece( dragPiece ); + dc.DrawBitmap( *img, mouseX-(SQUARE_HEIGHT/2), + mouseY-(SQUARE_WIDTH/2), true ); } } +wxBitmap *MainWindow::GetImageForPiece( const ChessPiece *piece ){ + wxBitmap *img; + ChessColor c = piece->color; + switch (piece->type){ + case CP_PAWN: img = (c==CLR_WHITE)?&whitePawn: &blackPawn;break; + case CP_ROOK: img = (c==CLR_WHITE)?&whiteRook: &blackRook;break; + case CP_KNIGHT:img = (c==CLR_WHITE)?&whiteKnight:&blackKnight;break; + case CP_BISHOP:img = (c==CLR_WHITE)?&whiteBishop:&blackBishop;break; + case CP_QUEEN: img = (c==CLR_WHITE)?&whiteQueen: &blackQueen;break; + case CP_KING: img = (c==CLR_WHITE)?&whiteKing: &blackKing;break; + + case CP_NOPIECE: + default: + img = NULL; + } + return img; +} + +//------------------------------------------------------------------------ +// Menu Functions +//------------------------------------------------------------------------ void MainWindow::OnQuit(wxCommandEvent& WXUNUSED(event)) { Close(TRUE); @@ -185,38 +197,83 @@ //----------------------------------------------------------------------- void MainWindow::OnMouseDown( wxMouseEvent& event ){ - bool rv; int row, col; - printf("Got a mouse down event!!\n"); - printf("located at (%d,%d)\n",event.m_x, event.m_y); - 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"); - dragging = true; - mouseX = event.m_x; - mouseY = event.m_y; - Refresh( false ); - Update(); + ChessBoard *board = ctl.GetCurrentBoard(); + const ChessPiece *piece; + bool onBoard; + bool shouldAllow; + const ChessSquare *from; + + onBoard = GetSquareFromPoint(event.m_x,event.m_y,row,col); + dragStartCol = col; + dragStartRow = row; + if( onBoard ){ + piece = board->GetPiece((ChessColumn)col, (ChessRow)row); + if(piece->type != CP_NOPIECE){ + //check to see if we should let it drag + from = board->GetSquare((ChessColumn)col, (ChessRow)row); + shouldAllow = ctl.ShouldAllowPiecePickup( *piece, *from); + if(shouldAllow){ + dragging = true; + mouseX = event.m_x; + mouseY = event.m_y; + dragPiece = piece; + dragStartX = event.m_x; + dragStartY = event.m_y; + Refresh( false ); + Update(); + ctl.PieceWasPickedUp( *piece, *from ); + } + } + } } 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 rv; - int row, col; - printf("Got a mouse up event!!\n"); - printf("located at (%d,%d)\n",event.m_x, event.m_y); - 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"); - dragging = false; - Refresh( false ); - Update(); + + bool onBoard; + bool shouldAllow; + int row, col; + const ChessPiece *captured; + ChessBoard *board = ctl.GetCurrentBoard(); + const ChessSquare *endSquare; + const ChessSquare *startSquare; + + onBoard = GetSquareFromPoint(event.m_x,event.m_y,row,col); + + startSquare = board->GetSquare((ChessColumn)dragStartCol, + (ChessRow)dragStartRow ); + + //see if it was a click + if( onBoard && col==dragStartCol && row==dragStartRow ){ + ctl.SquareWasSelected( row, col ); + } + + if(dragging){ + //if they released on a different square than they started + if( onBoard && (col!=dragStartCol || row!=dragStartRow)){ + endSquare = board->GetSquare((ChessColumn)col,(ChessRow)row); + captured = &endSquare->piece; + shouldAllow = ctl.ShouldAllowPiecePlacement(*dragPiece, *startSquare, + *endSquare, *captured); + + //check if we should move it + if( shouldAllow ){ + board->MovePiece(*startSquare, *endSquare); + } + //redraw + dragging = false; + Refresh( false ); + Update(); + + //inform that it was moved + if(shouldAllow){ + ctl.PieceWasPlaced(*dragPiece, *startSquare, *endSquare, *captured ); + } + } + dragging = false; + Refresh( false ); + Update(); + } } void MainWindow::OnMouseMove( wxMouseEvent& event ){ Modified: gui/MainWindow.h =================================================================== --- gui/MainWindow.h 2007-08-16 06:54:31 UTC (rev 51) +++ gui/MainWindow.h 2007-08-20 07:02:31 UTC (rev 52) @@ -25,8 +25,9 @@ void OnQuit(wxCommandEvent &event); void Redraw(wxPaintEvent &event); void OnSelectDrill(wxCommandEvent& event); - void OnMouseClick( wxMouseEvent& event ); + void OnMouseDown( wxMouseEvent& event ); void OnMouseUp( wxMouseEvent& event ); + void OnMouseMove( wxMouseEvent& event ); DECLARE_EVENT_TABLE() //PUBLIC METHODS @@ -68,7 +69,18 @@ blackBishop, whiteBishop, blackKing, whiteKing, blackQueen, whiteQueen; + //returns NULL if there is no image + wxBitmap *GetImageForPiece( const ChessPiece *piece ); + //Mouse stuff + bool dragging; + int mouseX; + int mouseY; + const ChessPiece *dragPiece; + int dragStartX; + int dragStartY; + int dragStartCol; + int dragStartRow; }; enum{ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pha...@us...> - 2007-08-16 06:54:32
|
Revision: 51 http://chessdrills.svn.sourceforge.net/chessdrills/?rev=51&view=rev Author: phantomfive Date: 2007-08-15 23:54:31 -0700 (Wed, 15 Aug 2007) Log Message: ----------- Now has some sort of weird piece movement. Really need to make the backgrounds of the images transparent (not to mention draw them to look good) Modified Paths: -------------- gui/GuiControl.cpp gui/MainWindow.cpp Modified: gui/GuiControl.cpp =================================================================== --- gui/GuiControl.cpp 2007-08-10 06:24:04 UTC (rev 50) +++ gui/GuiControl.cpp 2007-08-16 06:54:31 UTC (rev 51) @@ -75,6 +75,14 @@ //--------------------------------------------------------------- // Methods called by the GUI //--------------------------------------------------------------- +void GuiControl::SquareWasSelected( int &row, int &col ){ + const ChessSquare *sqr = board.GetSquare((ChessColumn)col, (ChessRow)row); + const ChessPiece *piece = &(sqr->piece); + if( currentDrill != NULL ){ + currentDrill->SquareWasSelected( *sqr, *piece ); + } +} + const char **GuiControl::GetDrillList(){ return DrillName; } Modified: gui/MainWindow.cpp =================================================================== --- gui/MainWindow.cpp 2007-08-10 06:24:04 UTC (rev 50) +++ gui/MainWindow.cpp 2007-08-16 06:54:31 UTC (rev 51) @@ -19,8 +19,9 @@ BEGIN_EVENT_TABLE(MainWindow, wxFrame) EVT_PAINT(MainWindow::Redraw) -EVT_LEFT_DOWN(MainWindow::OnMouseClick) +EVT_LEFT_DOWN(MainWindow::OnMouseDown) EVT_LEFT_UP(MainWindow::OnMouseUp) +EVT_MOTION(MainWindow::OnMouseMove) EVT_MENU(ID_Quit, MainWindow::OnQuit) EVT_MENU(ID_SelectDrill1, MainWindow::OnSelectDrill) EVT_MENU(ID_SelectDrill2, MainWindow::OnSelectDrill) @@ -65,6 +66,7 @@ CreateStatusBar(); SetStatusText( "Here is our board!" ); boardIsFlipped = false; + dragging = false; //create the menu wxMenu *menuFile = new wxMenu; @@ -157,6 +159,11 @@ } } } + + //dragging stuff + if( dragging ){ + dc.DrawBitmap( blackQueen, mouseX-(SQUARE_HEIGHT/2), mouseY-(SQUARE_WIDTH/2), true ); + } } void MainWindow::OnQuit(wxCommandEvent& WXUNUSED(event)) @@ -176,25 +183,50 @@ //----------------------------------------------------------------------- // Mouse functions //----------------------------------------------------------------------- -void MainWindow::OnMouseClick( wxMouseEvent& event ){ + +void MainWindow::OnMouseDown( wxMouseEvent& event ){ + bool rv; int row, col; - bool rv; printf("Got a mouse down event!!\n"); printf("located at (%d,%d)\n",event.m_x, event.m_y); 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"); + dragging = true; + mouseX = event.m_x; + mouseY = event.m_y; + Refresh( false ); + Update(); } void MainWindow::OnMouseUp( wxMouseEvent& event ){ - int row, col; + /*int row, col; bool rv; - rv = GetSquareFromPoint(event.m_x, event.m_y, row, col ); + rv = GetSquareFromPoint(event.m_x, event.m_y, row, col ); if( rv ){ ctl.SquareWasSelected( row, col ); } + */ + bool rv; + int row, col; + printf("Got a mouse up event!!\n"); + printf("located at (%d,%d)\n",event.m_x, event.m_y); + 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"); + dragging = false; + Refresh( false ); + Update(); } +void MainWindow::OnMouseMove( wxMouseEvent& event ){ + if( !dragging ) return; + mouseX = event.m_x; + mouseY = event.m_y; + Refresh( false ); + Update(); +} + bool MainWindow::GetSquareFromPoint(int x, int y, int &row, int &col){ if(boardIsFlipped){ row = y/SQUARE_HEIGHT; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pha...@us...> - 2007-08-10 06:24:12
|
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. |
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. |
From: <pha...@us...> - 2007-08-07 09:29:56
|
Revision: 48 http://chessdrills.svn.sourceforge.net/chessdrills/?rev=48&view=rev Author: phantomfive Date: 2007-08-07 02:28:51 -0700 (Tue, 07 Aug 2007) Log Message: ----------- starting to get mouse clicks working Modified Paths: -------------- gui/MainWindow.cpp gui/MainWindow.h Modified: gui/MainWindow.cpp =================================================================== --- gui/MainWindow.cpp 2007-08-06 03:11:09 UTC (rev 47) +++ gui/MainWindow.cpp 2007-08-07 09:28:51 UTC (rev 48) @@ -18,6 +18,8 @@ #define SQUARE_HEIGHT 64 BEGIN_EVENT_TABLE(MainWindow, wxFrame) +EVT_PAINT(MainWindow::Redraw) +EVT_LEFT_DOWN(MainWindow::OnMouseClick) EVT_MENU(ID_Quit, MainWindow::OnQuit) EVT_MENU(ID_SelectDrill1, MainWindow::OnSelectDrill) EVT_MENU(ID_SelectDrill2, MainWindow::OnSelectDrill) @@ -29,7 +31,6 @@ EVT_MENU(ID_SelectDrill8, MainWindow::OnSelectDrill) EVT_MENU(ID_SelectDrill9, MainWindow::OnSelectDrill) EVT_MENU(ID_SelectDrill10, MainWindow::OnSelectDrill) -EVT_PAINT(MainWindow::Redraw) END_EVENT_TABLE() //-------------------------------------------------------------------------- @@ -157,17 +158,6 @@ } } -void MainWindow::GetSquareFromPoint(int x, int y, int &row, int &col){ - if(boardIsFlipped){ - row = 8 - y/SQUARE_HEIGHT; - col = 8 - x/SQUARE_WIDTH; - } - else{ - row = y/SQUARE_HEIGHT; - col = x/SQUARE_WIDTH; - } -} - void MainWindow::OnQuit(wxCommandEvent& WXUNUSED(event)) { Close(TRUE); @@ -182,3 +172,26 @@ } +//----------------------------------------------------------------------- +// Mouse functions +//----------------------------------------------------------------------- +void MainWindow::OnMouseClick( wxMouseEvent& event ) +{ + int row, col; + 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); +} + +void MainWindow::GetSquareFromPoint(int x, int y, int &row, int &col){ + if(boardIsFlipped){ + row = y/SQUARE_HEIGHT; + col = x/SQUARE_WIDTH; + } + else{ + row = 7 - y/SQUARE_HEIGHT; + col = x/SQUARE_WIDTH; + } +} + Modified: gui/MainWindow.h =================================================================== --- gui/MainWindow.h 2007-08-06 03:11:09 UTC (rev 47) +++ gui/MainWindow.h 2007-08-07 09:28:51 UTC (rev 48) @@ -25,6 +25,7 @@ void OnQuit(wxCommandEvent &event); void Redraw(wxPaintEvent &event); void OnSelectDrill(wxCommandEvent& event); + void OnMouseClick( 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. |
From: <pha...@us...> - 2007-08-06 03:11:12
|
Revision: 47 http://chessdrills.svn.sourceforge.net/chessdrills/?rev=47&view=rev Author: phantomfive Date: 2007-08-05 20:11:09 -0700 (Sun, 05 Aug 2007) Log Message: ----------- SetSquare() now works, and the board draws correctly (though ugly) Modified Paths: -------------- base/ChessBoard.h drills/ExampleDrill.cpp gui/MainWindow.cpp Modified: base/ChessBoard.h =================================================================== --- base/ChessBoard.h 2007-08-04 07:03:01 UTC (rev 46) +++ base/ChessBoard.h 2007-08-06 03:11:09 UTC (rev 47) @@ -45,7 +45,7 @@ //removes all pieces and sets the board hilight/colors back to normal void Reset(); - + private: ChessSquare board[8][8]; }; Modified: drills/ExampleDrill.cpp =================================================================== --- drills/ExampleDrill.cpp 2007-08-04 07:03:01 UTC (rev 46) +++ drills/ExampleDrill.cpp 2007-08-06 03:11:09 UTC (rev 47) @@ -37,7 +37,6 @@ tempSquare.piece.color = CLR_WHITE; tempSquare.piece.type = CP_PAWN; SetSquare(theirPawn.col, theirPawn.row, tempSquare ); - //return true because we set up successfully return true; } Modified: gui/MainWindow.cpp =================================================================== --- gui/MainWindow.cpp 2007-08-04 07:03:01 UTC (rev 46) +++ gui/MainWindow.cpp 2007-08-06 03:11:09 UTC (rev 47) @@ -130,9 +130,8 @@ if( NULL != board ){ for(int i=0;i<8;i++){ for(int j=0;j<8;j++){ - const ChessPiece *piece = board->GetPiece((ChessColumn)i,(ChessRow)j); + const ChessPiece *piece = board->GetPiece((ChessColumn)j,(ChessRow)i); ChessColor c = piece->color; - printf("[%d,%d], type %d\n",i,j,piece->type); //find which piece and color switch (piece->type){ case CP_PAWN: img = (c==CLR_WHITE)?&whitePawn: &blackPawn;break; @@ -179,5 +178,7 @@ int id = event.GetId() - ID_SelectDrill1; const char ** menuList = ctl.GetDrillList(); ctl.SwitchToDrill( menuList[id] ); + Refresh(true); +} + -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pha...@us...> - 2007-08-04 07:03:04
|
Revision: 46 http://chessdrills.svn.sourceforge.net/chessdrills/?rev=46&view=rev Author: phantomfive Date: 2007-08-04 00:03:01 -0700 (Sat, 04 Aug 2007) Log Message: ----------- Fixed a seg fault (bugs already???) and some other minor issues Modified Paths: -------------- base/ChessBoard.cpp base/ChessDrill.cpp base/ChessDrill.h drills/DrillList.h drills/ExampleDrill.cpp gui/GuiControl.cpp gui/GuiControl.h gui/MainWindow.cpp Modified: base/ChessBoard.cpp =================================================================== --- base/ChessBoard.cpp 2007-08-02 07:40:05 UTC (rev 45) +++ base/ChessBoard.cpp 2007-08-04 07:03:01 UTC (rev 46) @@ -18,8 +18,7 @@ #define BOARD_HEIGHT 8 ChessPiece nopiece(CP_NOPIECE,CLR_DEFAULT); -ChessBoard::ChessBoard(){ - +ChessBoard::ChessBoard(){ Reset(); } @@ -71,7 +70,6 @@ //--------------------- // Clears the board //--------------------- -#include <stdio.h> void ChessBoard::Reset(){ int i,j; for(i=0; i<BOARD_WIDTH;i++) Modified: base/ChessDrill.cpp =================================================================== --- base/ChessDrill.cpp 2007-08-02 07:40:05 UTC (rev 45) +++ base/ChessDrill.cpp 2007-08-04 07:03:01 UTC (rev 46) @@ -69,10 +69,12 @@ gui->MovePiece(from, to, captured); } -void ChessDrill::SetSquare(const ChessPiece &piece, const ChessSquare &square){ - gui->SetSquare(piece, square); +void ChessDrill::SetSquare(const ChessColumn &col, const ChessRow &row, + const ChessSquare &square){ + gui->SetSquare(col, row, square); } + void ChessDrill::SetDescription(const std::string &description){ gui->SetDescription(description); } @@ -105,3 +107,6 @@ gui->SetUserColor(color); } +void ChessDrill::SetGuiControl( GuiControl *gui ){ + this->gui = gui; +} Modified: base/ChessDrill.h =================================================================== --- base/ChessDrill.h 2007-08-02 07:40:05 UTC (rev 45) +++ base/ChessDrill.h 2007-08-04 07:03:01 UTC (rev 46) @@ -103,9 +103,11 @@ //This allows you to set up a square any way you like, and erase what was //there before. - //PARAM piece - The square will now have this piece on it. - //PARAM square - The square to set. - void SetSquare(const ChessPiece &piece, const ChessSquare &square); + //PARAM col - the column of the square. + //PARAM row - the row of the square. + //PARAM square - The square to set. No need to set the column or row + void SetSquare(const ChessColumn &col, const ChessRow &row, + const ChessSquare &square); //Sets the description of the current drill void SetDescription(const std::string &description); @@ -155,6 +157,7 @@ void Enable(bool enable); //Pay o attention to the lines below this comment + void SetGuiControl( GuiControl *gui ); private: GuiControl *gui; }; Modified: drills/DrillList.h =================================================================== --- drills/DrillList.h 2007-08-02 07:40:05 UTC (rev 45) +++ drills/DrillList.h 2007-08-04 07:03:01 UTC (rev 46) @@ -1,6 +1,5 @@ /**************************************************************************** *A list for letting the program know what chess drills are available. - *This file should only be included by GuiControl.h * * To add your drill there are three things you must do: * 1. Add the header file for your drill @@ -9,6 +8,7 @@ * * Don't forget to add it to the makefile! * + *(This file should only be included by GuiControl.h) *Copyright 2007 Usable under the terms of the GPL ***************************************************************************/ #ifndef DRILL_LIST_H @@ -20,14 +20,14 @@ //When you write a new drill, include the correct header above, //and add your drill to this array. This name will appear in the //menu (the last element should be NULL). -const char *DrillName[2]={ +const char *DrillName[]={ "Example Drill", NULL }; //Here add an if statement that returns a new instance of your drill //when str is the same as the name above (it will be freed automatically) -ChessDrill *GetDrillByName( std::string &str ){ +ChessDrill *GetDrillByName( const std::string &str ){ if( str == "Example Drill" ) return (ChessDrill*)new ExampleDrill(); @@ -35,4 +35,6 @@ return NULL; } +#else +#error "Do not include DrillList.h!" #endif Modified: drills/ExampleDrill.cpp =================================================================== --- drills/ExampleDrill.cpp 2007-08-02 07:40:05 UTC (rev 45) +++ drills/ExampleDrill.cpp 2007-08-04 07:03:01 UTC (rev 46) @@ -18,7 +18,7 @@ //------------------------------------- bool ExampleDrill::Start(){ - ChessPiece tempPiece; + ChessSquare tempSquare; //first clear the board (not necessary, but just in case) ClearBoard(); @@ -26,16 +26,17 @@ //put my pawn on E5 myPawn.row = ROW_FIVE; myPawn.col = COL_A; - tempPiece.type = CP_PAWN; - tempPiece.color = CLR_BLACK; - SetSquare(tempPiece, myPawn); + tempSquare.piece.color = CLR_BLACK; + tempSquare.piece.type = CP_PAWN; + SetSquare(myPawn.col, myPawn.row, tempSquare); //put their pawn on A3 theirPawn.row = ROW_THREE; theirPawn.col = COL_A; - tempPiece.color = CLR_WHITE; - SetSquare(tempPiece,theirPawn); + tempSquare.piece.color = CLR_WHITE; + tempSquare.piece.type = CP_PAWN; + SetSquare(theirPawn.col, theirPawn.row, tempSquare ); //return true because we set up successfully return true; Modified: gui/GuiControl.cpp =================================================================== --- gui/GuiControl.cpp 2007-08-02 07:40:05 UTC (rev 45) +++ gui/GuiControl.cpp 2007-08-04 07:03:01 UTC (rev 46) @@ -14,7 +14,8 @@ // Constructor/Destructor //----------------------------------------------------------- GuiControl::GuiControl(){ - + currentDrill = NULL; + board.Reset(); } GuiControl::~GuiControl(){ @@ -34,8 +35,9 @@ board.MovePiece(from, to, captured); } -void GuiControl::SetSquare(const ChessPiece &piece, const ChessSquare &square){ - // board.SetSquare(square.col, square.row, piece); +void GuiControl::SetSquare(const ChessColumn &col, const ChessRow &row, + const ChessSquare &square){ + board.SetSquare(col, row, square); } void GuiControl::SetDescription(const std::string &description){ //Do nothing for now @@ -51,6 +53,7 @@ bool GuiControl::SendQueryAlert(const std::string &alertString){ //Do nothing for now + return false; } void GuiControl::DisplaySectionOfInstruction(const std::string &instructionString){ @@ -58,7 +61,7 @@ } void GuiControl::ClearBoard(){ - //Do nothing for now + board.Reset(); } void GuiControl::FinishDrill(){ @@ -76,8 +79,25 @@ return DrillName; } -void GuiControl::SwitchToDrill( std::string drill ){ - +void GuiControl::SwitchToDrill( const char *drill ){ + if( currentDrill != NULL ) + delete currentDrill; + std::string s(drill); + currentDrill = GetDrillByName( s ); + if( currentDrill == NULL ){ + printf("No drill for file name \"%s\". Please add it to ", + drill); + printf("DrillList.h,\n in the function GetDrillByName().\n"); + exit(-1); + } + currentDrill->SetGuiControl(this); + board.Reset(); + if( !currentDrill->Start() ){ + printf("Call to Drill Start returned false. Choose another drill\n"); + delete currentDrill; + currentDrill = NULL; + return; + } } ChessBoard *GuiControl::GetCurrentBoard(){ Modified: gui/GuiControl.h =================================================================== --- gui/GuiControl.h 2007-08-02 07:40:05 UTC (rev 45) +++ gui/GuiControl.h 2007-08-04 07:03:01 UTC (rev 46) @@ -19,6 +19,7 @@ class ChessSquare; class ChessPiece; +class ChessDrill; class GuiControl{ public: @@ -34,7 +35,8 @@ void MovePiece(const ChessSquare &from, const ChessSquare &to, ChessPiece &captured ); - void SetSquare(const ChessPiece &piece, const ChessSquare &square); + void SetSquare(const ChessColumn &col, const ChessRow &row, + const ChessSquare &square); void SetDescription(const std::string &description); @@ -60,7 +62,7 @@ const char** GetDrillList(); //Switches to the drill named by 'drill' - void SwitchToDrill( std::string drill ); + void SwitchToDrill( const char *drill ); //Returns the board to be used by the current drill, or an //empty board in case there is no drill in progress @@ -68,6 +70,7 @@ private: ChessBoard board; + ChessDrill *currentDrill; }; Modified: gui/MainWindow.cpp =================================================================== --- gui/MainWindow.cpp 2007-08-02 07:40:05 UTC (rev 45) +++ gui/MainWindow.cpp 2007-08-04 07:03:01 UTC (rev 46) @@ -132,6 +132,7 @@ for(int j=0;j<8;j++){ const ChessPiece *piece = board->GetPiece((ChessColumn)i,(ChessRow)j); ChessColor c = piece->color; + printf("[%d,%d], type %d\n",i,j,piece->type); //find which piece and color switch (piece->type){ case CP_PAWN: img = (c==CLR_WHITE)?&whitePawn: &blackPawn;break; @@ -177,9 +178,6 @@ { int id = event.GetId() - ID_SelectDrill1; const char ** menuList = ctl.GetDrillList(); - printf("in select drill\n"); - - printf("drill selected: %s\n",menuList[id]); ctl.SwitchToDrill( menuList[id] ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pha...@us...> - 2007-08-02 07:40:08
|
Revision: 45 http://chessdrills.svn.sourceforge.net/chessdrills/?rev=45&view=rev Author: phantomfive Date: 2007-08-02 00:40:05 -0700 (Thu, 02 Aug 2007) Log Message: ----------- Finally figured out that problem. Can now select a drill and the constructor will get called. Modified Paths: -------------- gui/MainWindow.cpp gui/MainWindow.h Modified: gui/MainWindow.cpp =================================================================== --- gui/MainWindow.cpp 2007-07-20 21:08:09 UTC (rev 44) +++ gui/MainWindow.cpp 2007-08-02 07:40:05 UTC (rev 45) @@ -19,7 +19,16 @@ BEGIN_EVENT_TABLE(MainWindow, wxFrame) EVT_MENU(ID_Quit, MainWindow::OnQuit) -EVT_MENU(ID_SelectDrill, MainWindow::OnSelectDrill) +EVT_MENU(ID_SelectDrill1, MainWindow::OnSelectDrill) +EVT_MENU(ID_SelectDrill2, MainWindow::OnSelectDrill) +EVT_MENU(ID_SelectDrill3, MainWindow::OnSelectDrill) +EVT_MENU(ID_SelectDrill4, MainWindow::OnSelectDrill) +EVT_MENU(ID_SelectDrill5, MainWindow::OnSelectDrill) +EVT_MENU(ID_SelectDrill6, MainWindow::OnSelectDrill) +EVT_MENU(ID_SelectDrill7, MainWindow::OnSelectDrill) +EVT_MENU(ID_SelectDrill8, MainWindow::OnSelectDrill) +EVT_MENU(ID_SelectDrill9, MainWindow::OnSelectDrill) +EVT_MENU(ID_SelectDrill10, MainWindow::OnSelectDrill) EVT_PAINT(MainWindow::Redraw) END_EVENT_TABLE() @@ -59,8 +68,8 @@ wxMenu *menuFile = new wxMenu; wxMenuBar *menuBar = new wxMenuBar; const char ** menuList = ctl.GetDrillList(); - for(int i=0;menuList[i]!=NULL;i++){ - menuFile->Append( ID_SelectDrill,menuList[i]); + for(int i=0, j=(int)ID_SelectDrill1;menuList[i]!=NULL;i++,j++){ + menuFile->Append( j, menuList[i] ); } menuFile->AppendSeparator(); menuFile->Append( ID_Quit, "&Exit" ); @@ -166,6 +175,11 @@ void MainWindow::OnSelectDrill(wxCommandEvent& event) { - wxMenuItem *item = (wxMenuItem *)event.GetObject(); - printf("drill selected: %s\n",item->GetText()); + int id = event.GetId() - ID_SelectDrill1; + const char ** menuList = ctl.GetDrillList(); + printf("in select drill\n"); + + printf("drill selected: %s\n",menuList[id]); + ctl.SwitchToDrill( menuList[id] ); + } Modified: gui/MainWindow.h =================================================================== --- gui/MainWindow.h 2007-07-20 21:08:09 UTC (rev 44) +++ gui/MainWindow.h 2007-08-02 07:40:05 UTC (rev 45) @@ -24,6 +24,7 @@ MainWindow(const wxString &title, const wxPoint &pos, const wxSize &size); void OnQuit(wxCommandEvent &event); void Redraw(wxPaintEvent &event); + void OnSelectDrill(wxCommandEvent& event); DECLARE_EVENT_TABLE() //PUBLIC METHODS @@ -68,7 +69,17 @@ }; enum{ - ID_Quit = 1 + ID_Quit = 1, + ID_SelectDrill1, + ID_SelectDrill2, + ID_SelectDrill3, + ID_SelectDrill4, + ID_SelectDrill5, + ID_SelectDrill6, + ID_SelectDrill7, + ID_SelectDrill8, + ID_SelectDrill9, + ID_SelectDrill10 }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pha...@us...> - 2007-07-20 21:08:13
|
Revision: 44 http://chessdrills.svn.sourceforge.net/chessdrills/?rev=44&view=rev Author: phantomfive Date: 2007-07-20 14:08:09 -0700 (Fri, 20 Jul 2007) Log Message: ----------- An attempt to fix the menu problem Modified Paths: -------------- gui/MainWindow.cpp Modified: gui/MainWindow.cpp =================================================================== --- gui/MainWindow.cpp 2007-07-20 07:31:25 UTC (rev 43) +++ gui/MainWindow.cpp 2007-07-20 21:08:09 UTC (rev 44) @@ -60,10 +60,7 @@ wxMenuBar *menuBar = new wxMenuBar; const char ** menuList = ctl.GetDrillList(); for(int i=0;menuList[i]!=NULL;i++){ - char s[100]; - snprintf(s,sizeof(s),"&%s",menuList[i]); - s[sizeof(s)-1] = 0; - menuFile->Append( ID_SelectDrill,s,"what" ); + menuFile->Append( ID_SelectDrill,menuList[i]); } menuFile->AppendSeparator(); menuFile->Append( ID_Quit, "&Exit" ); @@ -169,5 +166,6 @@ void MainWindow::OnSelectDrill(wxCommandEvent& event) { - printf("drill selected: %s\n",event.GetString().c_str()); + wxMenuItem *item = (wxMenuItem *)event.GetObject(); + printf("drill selected: %s\n",item->GetText()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pha...@us...> - 2007-07-20 07:31:30
|
Revision: 43 http://chessdrills.svn.sourceforge.net/chessdrills/?rev=43&view=rev Author: phantomfive Date: 2007-07-20 00:31:25 -0700 (Fri, 20 Jul 2007) Log Message: ----------- Menu appears now and is selectable, but how to determine which menu item was selected? Modified Paths: -------------- gui/MainWindow.cpp Modified: gui/MainWindow.cpp =================================================================== --- gui/MainWindow.cpp 2007-07-16 07:09:28 UTC (rev 42) +++ gui/MainWindow.cpp 2007-07-20 07:31:25 UTC (rev 43) @@ -19,6 +19,7 @@ BEGIN_EVENT_TABLE(MainWindow, wxFrame) EVT_MENU(ID_Quit, MainWindow::OnQuit) +EVT_MENU(ID_SelectDrill, MainWindow::OnSelectDrill) EVT_PAINT(MainWindow::Redraw) END_EVENT_TABLE() @@ -30,6 +31,7 @@ wxFrame((wxFrame*)NULL, -1, title, pos, size){ wxImage::AddHandler(new wxGIFHandler); printf("starting to load file\n"); + //load the images if( !blackSquare.LoadFile("images/blackSquare.gif",wxBITMAP_TYPE_GIF) || !whiteSquare.LoadFile("images/whiteSquare.gif",wxBITMAP_TYPE_GIF) || !blackPawn.LoadFile("images/blackPawn.gif",wxBITMAP_TYPE_GIF) || @@ -52,6 +54,21 @@ CreateStatusBar(); SetStatusText( "Here is our board!" ); boardIsFlipped = false; + + //create the menu + wxMenu *menuFile = new wxMenu; + wxMenuBar *menuBar = new wxMenuBar; + const char ** menuList = ctl.GetDrillList(); + for(int i=0;menuList[i]!=NULL;i++){ + char s[100]; + snprintf(s,sizeof(s),"&%s",menuList[i]); + s[sizeof(s)-1] = 0; + menuFile->Append( ID_SelectDrill,s,"what" ); + } + menuFile->AppendSeparator(); + menuFile->Append( ID_Quit, "&Exit" ); + menuBar->Append( menuFile, "&File" ); + SetMenuBar( menuBar ); } //------------------------------------------------------------------------- @@ -80,7 +97,6 @@ void MainWindow::Redraw(wxPaintEvent &event){ wxPaintDC dc(this); - printf("redrawing board\n"); DrawBoard(dc, ctl.GetCurrentBoard()); } @@ -150,3 +166,8 @@ { Close(TRUE); } + +void MainWindow::OnSelectDrill(wxCommandEvent& event) +{ + printf("drill selected: %s\n",event.GetString().c_str()); +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |