1 /****************************************************************************
2 
3  Copyright (C) 2002-2014 Gilles Debunne. All rights reserved.
4 
5  This file is part of the QGLViewer library version 2.7.2.
6 
7  http://www.libqglviewer.com - contact@libqglviewer.com
8 
9  This file may be used under the terms of the GNU General Public License
10  versions 2.0 or 3.0 as published by the Free Software Foundation and
11  appearing in the LICENSE file included in the packaging of this file.
12  In addition, as a special exception, Gilles Debunne gives you certain
13  additional rights, described in the file GPL_EXCEPTION in this package.
14 
15  libQGLViewer uses dual licensing. Commercial/proprietary software must
16  purchase a libQGLViewer Commercial License.
17 
18  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
19  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 
21 *****************************************************************************/
22 
23 #ifndef DVONNVIEWER_H
24 #define DVONNVIEWER_H
25 
26 #include "game.h"
27 
28 #include <QGLViewer/qglviewer.h>
29 #include <list>
30 
31 class QTimer;
32 
33 namespace dvonn {
34 class Game;
35 class Drawer;
36 } // namespace dvonn
37 
38 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
39 // Interface of DvonnViewer
40 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41 class DvonnViewer : public QGLViewer {
42   Q_OBJECT
43 
44 public:
45 #if QT_VERSION < 0x040000
46   DvonnViewer(QWidget *parent = NULL, const char *name = 0);
47 #else
48   DvonnViewer(QWidget *parent = NULL);
49 #endif
50   ~DvonnViewer();
51   void setGame(dvonn::Game *g);
52   void fadeOut(const dvonn::Board::Ghosts *g);
53   void animateMove(dvonn::Game::Move m);
54   void stopAllAnimations();
55 Q_SIGNALS:
56   void requested(dvonn::Game::Placement);
57   void requested(dvonn::Game::Move);
58 public Q_SLOTS:
59   void toggleTexture(bool);
60   void toggleLight(bool);
61   void toggleShowPossible(bool);
62   void toggleShowStatus(bool);
63   void toggleShowLabels(bool);
64   void toggleShowAnimation(bool);
65   void toggleDragToPlay(bool);
66   void animateScore();
67 protected Q_SLOTS:
68   void advanceFadeOut();
69   void advanceAnimateMove();
70   void advanceAnimateScore();
71 
72 protected:
73   virtual void init();
74   void initOpenGL();
75   void initSpotLight();
76   void initViewer();
77   virtual void draw();
78   void drawAllPieces(bool pick = false);
79   void drawAllSpaces(bool pick = false);
80   virtual void drawWithNames();
81   virtual void postSelection(const QPoint &point);
82   virtual QString helpString() const;
83 
84   virtual void keyPressEvent(QKeyEvent *e);
85   virtual void mousePressEvent(QMouseEvent *e);
86   virtual void mouseMoveEvent(QMouseEvent *e);
87   virtual void mouseReleaseEvent(QMouseEvent *e);
88   void commitDstPicked();
89 
90 private:
91   dvonn::Game *game_;
92   dvonn::Drawer *drawer_;
93 
94   int selectionMode_;
95   bool piecePicked_;
96   dvonn::Board::ConstStackHandle dstPicked_;
97   dvonn::Board::ConstStackHandle srcPicked_;
98   bool showPossDest_;
99   bool showStatus_;
100   bool showLabels_;
101   bool useLight_;
102   std::deque<dvonn::Board::ConstStackHandle> possDests_;
103   bool dragToPlay_;
104   const dvonn::Board::Ghosts *fadeGhosts_;
105   QTimer *fadeTimer_;
106   float fadeAlpha_;
107   QTimer *animateTimer_;
108   float animateT_;
109   dvonn::Game::Move animateMove_;
110   bool showAnimation_;
111   QTimer *scoreTimer_;
112   float scoreT_;
113   dvonn::Game::Move scoreMove_;
114 };
115 #endif // DVONNVIEWER_H
116