(C++) WtChess

January 25, 2018 · View on GitHub

 

 

 

 

 

(C++) WtChess

 

WtQt
CreatorLubuntu

 

CppWtChess is a Wt class to display a chess game.

Technical facts

 

 

 

 

 

 

./CppWtChess/wtchessboardwidget.h

 


 

 

 

 

 

./CppWtChess/wtchessboardwidget.cpp

 


 

 

 

 

 

./CppWtChess/wtchessresources.h

 


#ifndef WTCHESSRESOURCES_H #define WTCHESSRESOURCES_H //--------------------------------------------------------------------------- #include <boost/shared_ptr.hpp> #include "chessfwd.h" #include "chessresources.h" //--------------------------------------------------------------------------- namespace Chess { struct Piece; } namespace Wt { struct QPixmap; } //--------------------------------------------------------------------------- namespace Chess { //--------------------------------------------------------------------------- ///WtResources uses Wt for generating the chess resources struct WtResources : public Chess::Resources {   //WtResources constructor does all the work   WtResources();   ///Obtain the QPixmap of a Piece   const Wt::QPixmap& GetPiece(const Square& s) const;   ///Obtain the QPixmap of a Square   const Wt::QPixmap& GetSquare(const Square& s) const;   ///Obtain the version of this class   static const std::string GetVersion();   ///Obtain the version history of this class   static const std::vector<std::string> GetVersionHistory();   private:   boost::shared_ptr<Wt::QPixmap> m_square_black;   boost::shared_ptr<Wt::QPixmap> m_square_white; }; //--------------------------------------------------------------------------- } //~ namespace Chess //--------------------------------------------------------------------------- #endif // WTCHESSRESOURCES_H

 

 

 

 

 

./CppWtChess/wtchessresources.cpp

 


//--------------------------------------------------------------------------- #include <cassert> #include <iostream> //--------------------------------------------------------------------------- #include <boost/filesystem.hpp> //--------------------------------------------------------------------------- #include <QFile> //--------------------------------------------------------------------------- #include "chessresources.h" #include "wtchessresources.h" //--------------------------------------------------------------------------- namespace Chess { //--------------------------------------------------------------------------- WtResources::WtResources() {   const std::vector<std::string> v = Resources::GetFilenames();   std::for_each(v.begin(),v.end(),     [](const std::string& s)     {       if (!boost::filesystem::exists(s))       {         QFile f( (std::string(":/images/") + s).c_str() );         f.copy(s.c_str());         if (!boost::filesystem::exists(s.c_str()))         {           const std::string error = "File not found: " + s;           std::cerr << error << '\n';           std::clog << error << '\n';           std::cout << error << '\n';         }       }       assert(boost::filesystem::exists(s.c_str()));     }   ); } //--------------------------------------------------------------------------- const std::string WtResources::GetVersion() {   return "1.0"; } //--------------------------------------------------------------------------- const std::vector<std::string> WtResources::GetVersionHistory() {   std::vector<std::string> v;   v.push_back("2012-01-27: version 1.0: initial version");   return v; } //--------------------------------------------------------------------------- } //~ namespace Chess //---------------------------------------------------------------------------