Tactics: Western Philosophers Vs. Musicians  0.12
A turn-based tactical game combining rules and gameplay elements inspired by Final Fantasy Tactics and the Mayfair Exponential Game System. Unlike most games of this type, motion is in full, grid-less 3D.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GUI.h
Go to the documentation of this file.
1 // Copyright (C) 2004-2014 Dylan Blair
3 //
4 // email: dblair@alumni.cs.utexas.edu
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 
21 #ifndef GUI_H
22 #define GUI_H
23 
24 #include "GOgreApp.h"
25 #include "GUIScreen.h"
26 
27 #include <RendererModules/Ogre/CEGUIOgreRenderer.h>
28 #include <RendererModules/Ogre/CEGUIOgreResourceProvider.h>
29 
30 #include <OgreStringConverter.h>
31 #include <OgreException.h>
32 
33 #include <SdkTrays.h>
34 
35 #include <stack>
36 
37 #ifndef _WIN32
38 typedef void (__attribute__((stdcall)) *NodePickedCallback)(const char* name_);
39 #else
40 typedef void (__stdcall *NodePickedCallback)(const char* name_);
41 #endif
42 
43 namespace OpenSkyNet {
44  namespace Graphics {
45  class UI;
46 
48  class InputListener : public OIS::KeyListener, public OIS::MouseListener {
49  public:
51  CEGUI::Renderer* _gUIRenderer;
52  Ogre::SceneNode* _topNode;
53  Ogre::SceneNode* _currPickedNode;
54  Ogre::Camera* _cam;
55  NodePickedCallback _nodePickedCallback;
56 
58  Ogre::Vector3 _rayDirection, _rayOrigin;
59 
62 
63  virtual ~InputListener() {}
64 
65  virtual bool keyPressed(const OIS::KeyEvent& arg);
66  virtual bool keyReleased(const OIS::KeyEvent& arg);
67 
68  virtual void pickNode(Ogre::SceneNode* node_);
69  inline void setNodePickedCallback(NodePickedCallback nodePickedCallback_) { _nodePickedCallback = nodePickedCallback_; }
70 
71  virtual bool mouseMoved(const OIS::MouseEvent& arg);
72 
75  virtual bool mousePressed(const OIS::MouseEvent& arg, OIS::MouseButtonID id);
76 
77  virtual bool mouseReleased(const OIS::MouseEvent& arg, OIS::MouseButtonID id);
78  };
79 
82  class UI : public OgreApp, public Ogre::FrameListener, public Ogre::WindowEventListener, public OgreBites::SdkTrayListener {
84  protected:
85  CEGUI::OgreRenderer* _gUIRenderer;
86  CEGUI::System* _gUISystem;
87  std::stack<UIScreen*> _screens;
88 
90  Ogre::Real _moveSpeed, _rotateSpeed;
92  bool _statsOn;
94 
95  // To stop toggles flipping too fast
97 
99  Ogre::Vector3 _translateVector;
100  int _aniso;
101  Ogre::TextureFilterOptions _filtering;
102  float _rotX, _rotY;
104 
105  //OIS Input devices
106  OIS::InputManager* _inputManager;
107  OIS::Mouse* _mouse;
108  OIS::Keyboard* _keyboard;
110 
111  //Manages simple GUI components using the OGRE Overlay system (NOT CEGUI)
112  OgreBites::SdkTrayManager* _trayManager;
113 
114  volatile bool _quit;
115  Ogre::Vector3 _trans;
116 
117  Ogre::DisplayString _debugText;
118  public:
119  UI(InputListener* inputListener_=0);
120 
123  virtual bool setup(bool restoreOgreConfig_);
124  inline void setTopNodeForMousePicking(Ogre::SceneNode* n_=0) { _inputListener->_topNode = n_; }
125  virtual void setupEventHandlers() {}
127 
130  inline UIScreen* getTopScreen() const { return (_screens.empty() ? 0 : _screens.top()); }
131  virtual void pushScreen(UIScreen* screen_);
132  virtual void popScreen(bool doUnload_=true);
133  inline void popAndUnloadScreenNextUpdate() { if (!_screens.empty()) _screens.top()->popAndUnloadScreenNextUpdate(); }
135 
136  inline void setCanTranslateCam(bool val_) { _canTranslateCam = val_; }
137  inline void setCanRotateCam(bool val_) { _canRotateCam = val_; }
138 
141  virtual void moveCamera() {
142  using namespace Ogre;
143 
144  if (_canRotateCam) {
145  _camera->yaw(Degree(_rotX));
146  _camera->pitch(Degree(_rotY));
147  }
148 
149  if (_canTranslateCam)
150  _camera->moveRelative(_translateVector);
151  }
152 
153  inline void showDebugOverlay(bool show_) {
154  if (show_)
155  _trayManager->showFrameStats(OgreBites::TL_BOTTOMRIGHT);
156  else
157  _trayManager->hideFrameStats();
158  }
159 
162  virtual bool processUnbufferedKeyInput(const Ogre::FrameEvent& evt);
163  virtual bool processUnbufferedMouseInput(const Ogre::FrameEvent& evt);
164 
165  virtual void windowResized(Ogre::RenderWindow* rw);
166  virtual void windowClosed(Ogre::RenderWindow* rw);
167 
168  virtual bool frameStarted(const Ogre::FrameEvent& evt);
169  virtual bool frameEnded(const Ogre::FrameEvent& evt) {
170  _trayManager->frameRenderingQueued(evt);
171  return true;
172  }
174 
177  virtual void switchMouseMode() {
178  if (!_useBufferedInputMouse && _timeUntilNextToggle > 0.0f) return;
181  _mouse->setEventCallback(_inputListener);
182  else
183  _mouse->setEventCallback(0);
184 
185  if (!_screens.empty())
186  _screens.top()->switchMouseMode();
187 
188  _timeUntilNextToggle = 0.25f;
189  }
190 
191  virtual void switchKeyMode() {
194  _keyboard->setEventCallback(_inputListener);
195  else
196  _keyboard->setEventCallback(0);
197  }
198 
201 
203  virtual void destroyScene(bool doDestroyPersistentData_);
204 
205  inline void quit() { _quit = true; }
206 
207  static CEGUI::MouseButton convertOISMouseButtonToCegui(OIS::MouseButtonID buttonID_);
208  static bool doesHitAABB(const Ogre::AxisAlignedBox& AABB_, const Ogre::Vector3& origin_, const Ogre::Vector3& direction_);
209 
210  virtual ~UI();
211  };
212  }
213 }
214 
215 #endif //GUI_H
virtual void popScreen(bool doUnload_=true)
Definition: GUI.cpp:343
void showDebugOverlay(bool show_)
Definition: GUI.h:153
float _rotY
Definition: GUI.h:102
volatile bool _quit
Definition: GUI.h:114
virtual bool keyPressed(const OIS::KeyEvent &arg)
virtual bool setup(bool restoreOgreConfig_)
Definition: GUI.cpp:272
CEGUI::System * _gUISystem
Definition: GUI.h:86
Ogre::Vector3 _rayDirection
Definition: GUI.h:58
bool _useBufferedInputKeys
Definition: GUI.h:89
Ogre::Real _rotateSpeed
Definition: GUI.h:90
Ogre::Camera * _camera
Definition: GOgreApp.h:37
bool _statsOn
Definition: GUI.h:92
void setCanRotateCam(bool val_)
Definition: GUI.h:137
Graphics::UI * _UI
Definition: GUI.h:50
virtual ~InputListener()
Definition: GUI.h:63
virtual bool mouseMoved(const OIS::MouseEvent &arg)
Definition: GUI.cpp:168
virtual void switchKeyMode()
Definition: GUI.h:191
Ogre::Real _timeUntilNextToggle
Definition: GUI.h:96
virtual bool frameEnded(const Ogre::FrameEvent &evt)
Definition: GUI.h:169
Ogre::Vector3 _rayOrigin
Definition: GUI.h:58
virtual void moveCamera()
Definition: GUI.h:141
static CEGUI::MouseButton convertOISMouseButtonToCegui(OIS::MouseButtonID buttonID_)
Definition: GUI.cpp:20
static bool doesHitAABB(const Ogre::AxisAlignedBox &AABB_, const Ogre::Vector3 &origin_, const Ogre::Vector3 &direction_)
Definition: GUI.cpp:30
virtual void destroyScene(bool doDestroyPersistentData_)
Definition: GUI.cpp:373
void setCanTranslateCam(bool val_)
Definition: GUI.h:136
void __attribute__((stdcall)) nodePickedCallback(const char *name_)
Definition: ViewerDLL.cpp:55
std::stack< UIScreen * > _screens
Definition: GUI.h:87
void setTopNodeForMousePicking(Ogre::SceneNode *n_=0)
Definition: GUI.h:124
virtual void pushScreen(UIScreen *screen_)
Definition: GUI.cpp:336
virtual bool frameStarted(const Ogre::FrameEvent &evt)
Definition: GUI.cpp:445
Ogre::Real _moveSpeed
Definition: GUI.h:90
virtual bool keyReleased(const OIS::KeyEvent &arg)
Utils::uint _numScreenShots
Definition: GUI.h:93
virtual void setupEventHandlers()
Definition: GUI.h:125
bool _canRotateCam
Definition: GUI.h:103
float _rotX
Definition: GUI.h:102
void quit()
Definition: GUI.h:205
typedef void(__attribute__((stdcall))*NodePickedCallback)(const char *name_)
OgreBites::SdkTrayManager * _trayManager
Definition: GUI.h:112
UI(InputListener *inputListener_=0)
Definition: GUI.cpp:360
virtual void windowResized(Ogre::RenderWindow *rw)
Definition: GUI.cpp:419
CEGUI::OgreRenderer * _gUIRenderer
Definition: GUI.h:85
NodePickedCallback _nodePickedCallback
Definition: GUI.h:55
unsigned int uint
Definition: UTypes.h:39
Ogre::Vector3 _trans
Definition: GUI.h:115
virtual void switchMouseMode()
Definition: GUI.h:177
InputListener * _inputListener
Definition: GUI.h:109
Ogre::DisplayString _debugText
Definition: GUI.h:117
virtual void pickNode(Ogre::SceneNode *node_)
InputListener * getInputListener()
Definition: GUI.h:199
virtual bool processUnbufferedMouseInput(const Ogre::FrameEvent &evt)
Definition: GUI.cpp:407
float _rotScale
Definition: GUI.h:91
bool _useBufferedInputMouse
Definition: GUI.h:89
UIScreen * getTopScreen() const
Definition: GUI.h:130
OIS::Keyboard * _keyboard
Definition: GUI.h:108
virtual bool processUnbufferedKeyInput(const Ogre::FrameEvent &evt)
Definition: GUI.cpp:402
Ogre::Camera * _cam
Definition: GUI.h:54
void popAndUnloadScreenNextUpdate()
Definition: GUI.h:133
Definition: GUIScreen.h:63
Ogre::TextureFilterOptions _filtering
Definition: GUI.h:101
void setNodePickedCallback(NodePickedCallback nodePickedCallback_)
Definition: GUI.h:69
CEGUI::Renderer * _gUIRenderer
Definition: GUI.h:51
virtual bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
Definition: GUI.cpp:254
virtual bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
Definition: GUI.cpp:174
Definition: GOgreApp.h:34
Ogre::SceneNode * _topNode
Definition: GUI.h:52
float _moveScale
Definition: GUI.h:91
virtual void windowClosed(Ogre::RenderWindow *rw)
Definition: GUI.cpp:430
bool _canTranslateCam
Definition: GUI.h:103
Ogre::SceneNode * _currPickedNode
Definition: GUI.h:53
int _sceneDetailIndex
Definition: GUI.h:98
Definition: GUI.h:82
virtual ~UI()
Definition: GUI.cpp:381
InputListener()
Definition: GUI.h:60
int _aniso
Definition: GUI.h:100
Ogre::Vector3 _translateVector
Definition: GUI.h:99
OIS::InputManager * _inputManager
Definition: GUI.h:106
OIS::Mouse * _mouse
Definition: GUI.h:107