[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Camino-devel] camino/src/client BoardCanvas.h BoardCanvas.cpp
From: |
Pascal Audoux |
Subject: |
[Camino-devel] camino/src/client BoardCanvas.h BoardCanvas.cpp |
Date: |
Sun, 02 Mar 2003 16:26:21 -0500 |
CVSROOT: /cvsroot/camino
Module name: camino
Changes by: Pascal Audoux <address@hidden> 03/03/02 16:26:21
Modified files:
src/client : BoardCanvas.h BoardCanvas.cpp
Log message:
change addTile method
add removeTile methode
add destructor
add reupdate method
Patches:
Index: camino/src/client/BoardCanvas.cpp
diff -u camino/src/client/BoardCanvas.cpp:1.8
camino/src/client/BoardCanvas.cpp:1.9
--- camino/src/client/BoardCanvas.cpp:1.8 Thu Feb 27 12:25:50 2003
+++ camino/src/client/BoardCanvas.cpp Sun Mar 2 16:26:21 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: BoardCanvas.cpp,v 1.8 2003/02/27 17:25:50 pfremy Exp $
+** Version : $Id: BoardCanvas.cpp,v 1.9 2003/03/02 21:26:21 Audoux Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 22/01/2003
@@ -37,24 +37,57 @@
: QCanvas( parent, name )
{
_margin = 2;
- resize( Theme::getTheme()->getTileSize() * Camino::nbVerTiles,
- Theme::getTheme()->getTileSize() * Camino::nbHorTiles );
+ resize( (Theme::getTheme()->getTileSize() * Camino::nbHorTiles) + ( 2 *
_margin ),
+ (Theme::getTheme()->getTileSize() * Camino::nbVerTiles)
+ ( 2 * _margin ) );
setBackgroundColor( Qt::black );
+
+ for( int i = 0; i < Camino::nbVerTiles; i++ ) {
+ for( int j = 0; j < Camino::nbHorTiles; j++ ) {
+ _board[i][j] = new TileSprite( this, i, j );
+ }
+ }
+}
+
+BoardCanvas::~BoardCanvas()
+{
+ for( int i = 0; i < Camino::nbVerTiles; i++ ) {
+ for( int j = 0; j < Camino::nbHorTiles; j++ ) {
+ delete _board[i][j];
+ _board[i][j] = 0;
+ }
+ }
}
void BoardCanvas::addTile( Tile * tile )
{
- int x,y;
int row = tile->getRow();
int col = tile->getCol();
- rowCol2xy( row, col, &x, &y );
- TileSprite * sprite = new TileSprite( this );
- sprite->move( x, y );
- sprite->show();
+ _board[row][col]->setType( tile->getType() );
+ _board[row][col]->setRotation( tile->getRotation() );
+}
+
+void BoardCanvas::removeTile( Tile * tile )
+{
+ int row = tile->getRow();
+ int col = tile->getCol();
+ _board[row][col]->cancelRotation();
+ _board[row][col]->setType( Tile::TILE_UNKNOWN );
}
void BoardCanvas::clear()
{
+ for( int i = 0; i < Camino::nbVerTiles; i++ ) {
+ for( int j = 0; j < Camino::nbHorTiles; j++ ) {
+ _board[i][j]->cancelRotation();
+ _board[i][j]->setType( Tile::TILE_UNKNOWN );
+ }
+ }
+}
+
+void BoardCanvas::reupdate()
+{
+ resize( (Theme::getTheme()->getTileSize() * Camino::nbHorTiles) + ( 2 *
_margin ),
+ (Theme::getTheme()->getTileSize() * Camino::nbVerTiles) + ( 2 *
_margin ) );
}
@@ -67,7 +100,7 @@
p.setPen( color );
for (col=0; col < Camino::nbHorTiles; col++ ) {
for (row=0; row < Camino::nbVerTiles; row++ ) {
- rowCol2xy( row, col, &x, &y );
+ rowCol2xy( row, col, &x, &y );
p.drawRect( x, y, tileSize, tileSize );
}
}
Index: camino/src/client/BoardCanvas.h
diff -u camino/src/client/BoardCanvas.h:1.5 camino/src/client/BoardCanvas.h:1.6
--- camino/src/client/BoardCanvas.h:1.5 Thu Feb 27 08:35:15 2003
+++ camino/src/client/BoardCanvas.h Sun Mar 2 16:26:21 2003
@@ -5,7 +5,7 @@
** BoardCanvas.h
** Canvas for the board view
**
-** Version : $Id: BoardCanvas.h,v 1.5 2003/02/27 13:35:15 pfremy Exp $
+** Version : $Id: BoardCanvas.h,v 1.6 2003/03/02 21:26:21 Audoux Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 22/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -32,8 +32,10 @@
// include files for QT
#include <qcanvas.h>
// application specific include files
+#include "common/const.h"
class Tile;
+class TileSprite;
/* ------------------------------
* BoardCanvas
@@ -50,9 +52,14 @@
/** Constructor */
BoardCanvas( QWidget * parent = 0, const char * name = 0 );
+ virtual ~BoardCanvas();
+
void addTile( Tile * tile );
+ void removeTile( Tile * tile );
void clear();
+ void reupdate();
+
//! tranform row,col into x,y : to use all the time
void rowCol2xy( int row, int col, int * x, int * y );
//! tranform x,y into row,col : to use all the time
@@ -60,7 +67,9 @@
protected:
virtual void drawBackground ( QPainter & painter, const QRect & clip );
+
int _margin;
+ TileSprite * _board[Camino::nbVerTiles][Camino::nbHorTiles];
friend class BoardView;
};
- [Camino-devel] camino/src/client BoardCanvas.h BoardCanvas.cpp,
Pascal Audoux <=