camino-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Camino-devel] camino/src/client ClientInterface.cpp BoardCanv...


From: Philippe Fremy
Subject: [Camino-devel] camino/src/client ClientInterface.cpp BoardCanv...
Date: Thu, 27 Feb 2003 05:21:26 -0500

CVSROOT:        /cvsroot/camino
Module name:    camino
Changes by:     Philippe Fremy <address@hidden> 03/02/27 05:21:24

Modified files:
        src/client     : ClientInterface.cpp BoardCanvas.cpp Theme.h 
                         Theme.cpp 

Log message:
        simplified theme handling

Patches:
Index: camino/src/client/BoardCanvas.cpp
diff -u camino/src/client/BoardCanvas.cpp:1.4 
camino/src/client/BoardCanvas.cpp:1.5
--- camino/src/client/BoardCanvas.cpp:1.4       Tue Feb 18 17:16:10 2003
+++ camino/src/client/BoardCanvas.cpp   Thu Feb 27 05:21:22 2003
@@ -2,7 +2,7 @@
 **
 ** Camino
 **
-** Version : $Id: BoardCanvas.cpp,v 1.4 2003/02/18 22:16:10 Audoux Exp $
+** Version : $Id: BoardCanvas.cpp,v 1.5 2003/02/27 10:21:22 pfremy Exp $
 **
 ** Author(s) : Philippe Fremy, Pascal Audoux
 ** Creation : 22/01/2003
@@ -31,12 +31,10 @@
 
 #include "BoardCanvas.h"
 
-extern Theme theme;
-
 BoardCanvas::BoardCanvas( QWidget * parent, const char * name )
        : QCanvas( parent, name )
 {
-       resize( theme.getZoomSize() * 10, theme.getZoomSize() * 14 );
+       resize( Theme::getTheme()->getZoomSize() * 10, 
Theme::getTheme()->getZoomSize() * 14 );
        setBackgroundColor( Qt::black );
 }
 
Index: camino/src/client/ClientInterface.cpp
diff -u camino/src/client/ClientInterface.cpp:1.21 
camino/src/client/ClientInterface.cpp:1.22
--- camino/src/client/ClientInterface.cpp:1.21  Tue Feb 18 17:17:26 2003
+++ camino/src/client/ClientInterface.cpp       Thu Feb 27 05:21:22 2003
@@ -2,7 +2,7 @@
 **
 ** Camino
 **
-** Version : $Id: ClientInterface.cpp,v 1.21 2003/02/18 22:17:26 Audoux Exp $
+** Version : $Id: ClientInterface.cpp,v 1.22 2003/02/27 10:21:22 pfremy Exp $
 **
 ** Author(s) : Philippe Fremy, Pascal Audoux
 ** Creation : 15/01/2003
@@ -40,14 +40,12 @@
 #include "server/ServerWidget.h"
 
 #include "client/CaminoSettings.h"
-#include "client/ClientEngine.h"
 #include "client/ClientInterface.h"
 #include "client/DialogConnection.h"
 #include "client/DialogTheme.h"
 #include "client/Game.h"
 #include "client/Theme.h"
 
-extern Theme theme;
 extern CaminoSettings settings;
 
 ClientInterface::ClientInterface( bool connectImmediately, 
@@ -62,7 +60,7 @@
        initActions();
        initMenuBar();
        initStatusBar();
-       theme.init( settings.getThemeName() );
+       Theme::getTheme()->init( settings.getThemeName() );
 
        _game = new Game( this );
        setCentralWidget( _game );
@@ -246,16 +244,16 @@
                _actions[ACT_ZOOMLARGE]->setOn( true );
                break;
        }
-       theme.setZoomLevel( level );
+       Theme::getTheme()->setZoomLevel( level );
        _game->reupdate();
 }
 
 void ClientInterface::chooseTheme()
 {
        DialogTheme themeDlg;
-       themeDlg.setTheme( theme.getName() );
+       themeDlg.setTheme( Theme::getTheme()->getName() );
        if( themeDlg.exec() ) {
-               theme.init( themeDlg.getTheme() );
+               Theme::getTheme()->init( themeDlg.getTheme() );
                settings.setThemeName( themeDlg.getTheme() );
        }
 }
Index: camino/src/client/Theme.cpp
diff -u camino/src/client/Theme.cpp:1.4 camino/src/client/Theme.cpp:1.5
--- camino/src/client/Theme.cpp:1.4     Sat Feb  1 06:13:17 2003
+++ camino/src/client/Theme.cpp Thu Feb 27 05:21:22 2003
@@ -2,7 +2,7 @@
 **
 ** Camino
 **
-** Version : $Id: Theme.cpp,v 1.4 2003/02/01 11:13:17 Audoux Exp $
+** Version : $Id: Theme.cpp,v 1.5 2003/02/27 10:21:22 pfremy Exp $
 **
 ** Author(s) : Philippe Fremy, Pascal Audoux
 ** Creation : 22/01/2003
@@ -27,10 +27,19 @@
 // include files for QT
 #include <qpixmap.h>
 #include <qptrlist.h>
+#include <qstring.h>
 // application specific include files
 #include "Theme.h"
 
-Theme theme;
+Theme * Theme::_theme = 0L;
+
+Theme * Theme::getTheme()
+{
+       if (_theme == 0L) {
+               _theme = new Theme();
+       }
+       return _theme;
+}
 
 /** add comments here */
 Theme::Theme()
@@ -38,6 +47,17 @@
        _level = 1;
        _tiles = 0;
        _name = "";
+
+       // Phil simplified theme
+       int t;
+       for (t=0; t<Tile::LAST_TILE; t++) {
+               QString filename = "themes/classic/" + filenameForType( 
(Tile::TileType) t );
+               pixmapArray[t] = QPixmap( filename );
+               if (pixmapArray[t].size() == QSize(0,0) ) {
+                       qDebug("Unable to load pixmap %s", filename.latin1() );
+               }
+               pixmapArray[t].resize( 85, 85 );
+       }
 }
 
 Theme::~Theme()
@@ -49,6 +69,10 @@
 
 void Theme::init( QString name )
 {
+
+       // ----
+       QPixmap * pixmap = 0L;
+       QString filename;
        if( _name != "" ) {
                clear();
        }
@@ -64,7 +88,12 @@
                                        list1.setAutoDelete( true );
                                        QPtrList<QPoint> list2;
                                        list2.setAutoDelete( true );
-                                       list1.append( new QPixmap( 
"./themes/classic/large/tile_0_0_0.png" ) );
+                                       filename =  
"./themes/classic/large/tile_0_0_0.png";
+                                       pixmap = new QPixmap( filename );
+                                       if (pixmap->size() == QSize(0,0) ) {
+                                               qDebug("Unable to load pixmap 
%s", filename.latin1() );
+                                       }
+                                       list1.append( pixmap );
                                        list2.append( new QPoint( 0, 0 ) );
                                        _tiles[i][j][k] = new 
QCanvasPixmapArray( list1, list2 );
                                }
@@ -116,14 +145,81 @@
 
 const QPixmap & Theme::getTilePixmap( int num, int side )
 {
+       QPixmap * pixmap;
        // XXX: add some checks...
        QCanvasPixmapArray * array = _tiles[_level-1][num][side];
-       return  *( array->image( 0 ) );
+       pixmap = array->image( 0 );
+       if (pixmap == 0L) {
+               qDebug("Theme::getTilePixmap() - null pixmap");
+       }
+       if (pixmap->size() == QSize(0,0) ) {
+               qDebug("Theme::getTilePixmap() - null size pixmap");
+       }
+       return *pixmap;
 }
 
 
+QString Theme::filenameForType( Tile::TileType tile )
+{
+       QString name = "unknown";
+       switch( tile ) {
+               case Tile::TILE_ROAD_STRAIGHT:
+                       name = "road_straight";
+                       break;
+               case Tile::TILE_ROAD_T:
+                       name = "road_t";
+                       break;
+               case Tile::TILE_ROAD_DEADEND:
+                       name = "road_dead_end";
+                       break;
+               case Tile::TILE_ROAD_TURN:
+                       name = "road_turn";
+                       break;
+               case Tile::TILE_ROAD_CROSS:
+                       name = "road_cross";
+                       break;
+               case Tile::TILE_RAIL_TURN:
+                       name = "rail_turn";
+                       break;
+               case Tile::TILE_RAIL_STRAIGHT:
+                       name = "rail_straight";
+                       break;
+               case Tile::TILE_RAIL_DEADEND:
+                       name = "rail_dead_end";
+                       break;
+               case Tile::TILE_RIVER_STRAIGHT:
+                       name = "river_straight";
+                       break;
+               case Tile::TILE_RIVER_TURN:
+                       name = "river_turn";
+                       break;
+               case Tile::TILE_CROSS_ROAD_RAIL:
+                       name = "cross_road_rail";
+                       break;
+               case Tile::TILE_CROSS_ROAD_RIVER:
+                       name = "cross_road_river";
+                       break;
+               case Tile::TILE_FOREST:
+                       name = "forest";
+                       break;
+               case Tile::TILE_PLAIN:
+                       name = "field";
+                       break;
+
+               case Tile::TILE_UNKNOWN:
+               default:
+                       name = "unknown";
+                       break;
+       }
+       name += ".png";
+       return name;
+}
 
 
+const QPixmap & Theme::pixmapForTile( Tile::TileType tile )
+{
+       return pixmapArray[ tile ];
+}
 
 
 
Index: camino/src/client/Theme.h
diff -u camino/src/client/Theme.h:1.4 camino/src/client/Theme.h:1.5
--- camino/src/client/Theme.h:1.4       Sat Feb  1 06:13:17 2003
+++ camino/src/client/Theme.h   Thu Feb 27 05:21:22 2003
@@ -5,7 +5,7 @@
 ** Theme.h
 ** Manage theme data and pictures
 **
-** Version : $Id: Theme.h,v 1.4 2003/02/01 11:13:17 Audoux Exp $
+** Version : $Id: Theme.h,v 1.5 2003/02/27 10:21:22 pfremy Exp $
 ** Author(s) : Philippe Fremy, Pascal Audoux
 ** Creation : 22/01/2003
 ** Copyright: Pascal Audoux, Philippe Fremy 2003
@@ -29,6 +29,7 @@
 
 
 // generic include files
+#include "common/Tile.h"
 // include files for QT
 #include <qcanvas.h>
 #include <qstring.h>
@@ -39,19 +40,23 @@
  *                         Theme
  *              ------------------------------ */
 
-
+class Theme;
 
 /** comment for the class */
 class Theme
 {
-
-public:
+private:
        /** Constructor */
        Theme();
 
        /** Destructor */
        virtual ~Theme();
 
+       static Theme * _theme;
+
+public:
+       static Theme * getTheme();
+
        /** Initializes the theme */
        void init( QString name );
 
@@ -67,9 +72,14 @@
 
        const QPixmap & getTilePixmap( int num, int side );
 
+       // simplified theme by philippe, until Pascal creates the real stuff
+       const QPixmap & pixmapForTile( Tile::TileType tile );
+       static QString filenameForType( Tile::TileType tile );
+
 protected:
+       QPixmap pixmapArray[ Tile::LAST_TILE ];
+
        void clear();
-       
        int _level;
        QString _name;
        QCanvasPixmapArray **** _tiles;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]