[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: |
Philippe Fremy |
Subject: |
[Camino-devel] camino/src/client BoardCanvas.h BoardCanvas.cpp... |
Date: |
Thu, 27 Feb 2003 08:35:17 -0500 |
CVSROOT: /cvsroot/camino
Module name: camino
Changes by: Philippe Fremy <address@hidden> 03/02/27 08:35:15
Modified files:
src/client : BoardCanvas.h BoardCanvas.cpp BoardView.h
BoardView.cpp
Log message:
- add method rowCol2xy and xy2rowCol to take care of the conversion,
taking into account margin, theme and size of tile
- try to draw a background frame for tile (does not work very well)
Patches:
Index: camino/src/client/BoardCanvas.cpp
diff -u camino/src/client/BoardCanvas.cpp:1.5
camino/src/client/BoardCanvas.cpp:1.6
--- camino/src/client/BoardCanvas.cpp:1.5 Thu Feb 27 05:21:22 2003
+++ camino/src/client/BoardCanvas.cpp Thu Feb 27 08:35:15 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: BoardCanvas.cpp,v 1.5 2003/02/27 10:21:22 pfremy Exp $
+** Version : $Id: BoardCanvas.cpp,v 1.6 2003/02/27 13:35:15 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 22/01/2003
@@ -24,7 +24,9 @@
// generic include files
// include files for QT
+#include <qpainter.h>
// application specific include files
+#include "common/const.h"
#include "common/Tile.h"
#include "client/Theme.h"
#include "client/TileSprite.h"
@@ -34,20 +36,50 @@
BoardCanvas::BoardCanvas( QWidget * parent, const char * name )
: QCanvas( parent, name )
{
- resize( Theme::getTheme()->getZoomSize() * 10,
Theme::getTheme()->getZoomSize() * 14 );
+ _margin = 2;
+ resize( Theme::getTheme()->getZoomSize() * Camino::nbVerTiles,
Theme::getTheme()->getZoomSize() * Camino::nbHorTiles );
setBackgroundColor( Qt::black );
}
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( (row-1) * 70, (col-1) * 70 );
- sprite->show();
+ sprite->move( x, y );
+ sprite->show();
}
void BoardCanvas::clear()
{
+}
+
+void BoardCanvas::drawBackground( QPainter & p, const QRect & /* clip */ )
+{
+ int row, col, x, y;
+ QColor color = QColor( blue );
+ int tileSize = Theme::getTheme()->getTileSize();
+ p.fillRect( rect(), QBrush( black ) );
+ p.setPen( color );
+ for (col=0; col < Camino::nbHorTiles; col++ ) {
+ for (row=0; row < Camino::nbVerTiles; row++ ) {
+ rowCol2xy( row, col, &x, &y );
+ p.drawRect( x, y, tileSize, tileSize );
+ }
+ }
+}
+
+void BoardCanvas::rowCol2xy( int row, int col, int * x, int * y )
+{
+ *x = _margin + col * Theme::getTheme()->getTileSize();
+ *y = _margin + row * Theme::getTheme()->getTileSize();
+}
+
+void BoardCanvas::xy2rowCol( int x, int y, int * row, int * col )
+{
+ *row = (x - _margin) / Theme::getTheme()->getTileSize();
+ *col = (y - _margin) / Theme::getTheme()->getTileSize();
}
Index: camino/src/client/BoardCanvas.h
diff -u camino/src/client/BoardCanvas.h:1.4 camino/src/client/BoardCanvas.h:1.5
--- camino/src/client/BoardCanvas.h:1.4 Tue Feb 18 17:16:10 2003
+++ camino/src/client/BoardCanvas.h Thu Feb 27 08:35:15 2003
@@ -5,7 +5,7 @@
** BoardCanvas.h
** Canvas for the board view
**
-** Version : $Id: BoardCanvas.h,v 1.4 2003/02/18 22:16:10 Audoux Exp $
+** Version : $Id: BoardCanvas.h,v 1.5 2003/02/27 13:35:15 pfremy Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 22/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -40,6 +40,7 @@
* ------------------------------ */
+class BoardView;
/** comment for the class */
class BoardCanvas : public QCanvas
@@ -50,8 +51,18 @@
BoardCanvas( QWidget * parent = 0, const char * name = 0 );
void addTile( Tile * tile );
-
void clear();
+
+ //! 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
+ void xy2rowCol( int x, int y, int * row, int * col );
+
+protected:
+ virtual void drawBackground ( QPainter & painter, const QRect & clip );
+ int _margin;
+
+friend class BoardView;
};
#endif // BOARDCANVAS_H
Index: camino/src/client/BoardView.cpp
diff -u camino/src/client/BoardView.cpp:1.3 camino/src/client/BoardView.cpp:1.4
--- camino/src/client/BoardView.cpp:1.3 Tue Feb 4 16:05:43 2003
+++ camino/src/client/BoardView.cpp Thu Feb 27 08:35:15 2003
@@ -2,7 +2,7 @@
**
** Camino
**
-** Version : $Id: BoardView.cpp,v 1.3 2003/02/04 21:05:43 Audoux Exp $
+** Version : $Id: BoardView.cpp,v 1.4 2003/02/27 13:35:15 pfremy Exp $
**
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 22/01/2003
@@ -28,7 +28,7 @@
// include files for QT
// application specific include files
#include "client/TileSprite.h"
-
+#include "client/Theme.h"
#include "client/BoardCanvas.h"
@@ -40,15 +40,22 @@
void BoardView::contentsMouseReleaseEvent( QMouseEvent * e )
{
- QCanvasItemList list = canvas()->collisions(e->pos());
- for( unsigned int i = 0; i < list.count(); i++ ) {
+ int row, col;
+
+ _board->xy2rowCol( e->x(), e->y(), &row, &col );
+ qDebug("BoardView::contentsMouseReleaseEvent - tile %dx%d clicked",
col, row );
+ emit sig_tileClicked( row, col );
+ /*
+ QCanvasItemList list = canvas()->collisions(e->pos());
+ for( unsigned int i = 0; i < list.count(); i++ ) {
if( list[i]->rtti() == TileSprite::RTTI ) {
if( e->button() == LeftButton ) {
TileSprite * tile = ( (TileSprite *)list[i] );
emit sig_tile( tile->getRow(), tile->getCol() );
}
}
- }
+ }
+ */
}
Index: camino/src/client/BoardView.h
diff -u camino/src/client/BoardView.h:1.2 camino/src/client/BoardView.h:1.3
--- camino/src/client/BoardView.h:1.2 Tue Feb 4 16:05:43 2003
+++ camino/src/client/BoardView.h Thu Feb 27 08:35:15 2003
@@ -5,7 +5,7 @@
** BoardView.h
** Display the board
**
-** Version : $Id: BoardView.h,v 1.2 2003/02/04 21:05:43 Audoux Exp $
+** Version : $Id: BoardView.h,v 1.3 2003/02/27 13:35:15 pfremy Exp $
** Author(s) : Philippe Fremy, Pascal Audoux
** Creation : 22/01/2003
** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -51,9 +51,10 @@
BoardView( BoardCanvas * board, QWidget * parent = 0, const char * name
= 0, WFlags f = 0 );
signals:
- void sig_tile( int row, int col );
+ void sig_tileClicked( int row, int col );
protected:
+
virtual void contentsMouseReleaseEvent( QMouseEvent * e );
BoardCanvas * _board;
- [Camino-devel] camino/src/client BoardCanvas.h BoardCanvas.cpp...,
Philippe Fremy <=