Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added Window-Events

Window closes when [x] is clicked (istead of Escape-key)
  • Loading branch information...
commit 4a960a73047e1a902394428c678183bb44f991b5 1 parent c79bd98
Michael authored
View
1  include/Core/GameApplication.hpp
@@ -50,6 +50,7 @@ class GameApplication : public singleton<GameApplication>
// Slots
void keyPressed(const OIS::KeyEvent &e);
+ void WindowClosing(Ogre::RenderWindow *rw, bool &shouldClose);
};
#endif
View
6 include/Managers/EventManager.hpp
@@ -20,7 +20,7 @@ using namespace boost::serialization;
// Define section
#define CONNECT0(EventType, EventName, FunctionPointer) EventManager::get_mutable_instance().connect<EventType>(EventName, bind(FunctionPointer, this));
#define CONNECT(EventType, EventName, FunctionPointer) EventManager::get_mutable_instance().connect<EventType>(EventName, bind(FunctionPointer, this, _1));
-#define CONNECT2(EventType, EventName, FunctionPointer) EventManager::get_mutable_instance().connect<EventType>(EventName, bind(FunctionPointer, this, _1, _1));
+#define CONNECT2(EventType, EventName, FunctionPointer) EventManager::get_mutable_instance().connect<EventType>(EventName, bind(FunctionPointer, this, _1, _2));
#define CONNECT_SINGLE(EventType, EventName, FunctionPointer) EventManager::get_mutable_instance().connect<EventType>(EventName, FunctionPointer);
#define SIGNAL(EventType, EventName, ...) EventManager::get_mutable_instance().get<EventType>(EventName)->Call(EventType::ArgsType(__VA_ARGS__));
@@ -51,7 +51,7 @@ class EventManager : public singleton<EventManager>
signalName));
return NULL;
}
-
+
try
{
return &any_cast<EventType&>(mSignalAssociation.at(signalName));
@@ -65,7 +65,7 @@ class EventManager : public singleton<EventManager>
}
return NULL;
}
-
+
template<typename EventType>
void create(const string &signalName)
{
View
3  include/Managers/Events/Events.hpp
@@ -28,6 +28,9 @@ namespace Engine
NEW_EVENT(void (void), GainFocusEvent);
NEW_EVENT(void (void), MouseEnteredEvent);
*/
+ NEW_EVENT(void (Ogre::RenderWindow *rw, bool &shouldClose), ClosingEvent);
+ NEW_EVENT(void (Ogre::RenderWindow *rw), WindowEvent);
+
NEW_EVENT(void (const OIS::KeyEvent &e), KeyEvent);
NEW_EVENT(void (const OIS::MouseEvent &e, const OIS::MouseButtonID &id), MouseButtonEvent);
NEW_EVENT(void (const OIS::MouseEvent &ed), MouseMoveEvent);
View
11 include/Systems/InputSystem.hpp
@@ -16,10 +16,13 @@
#include <OISKeyboard.h>
#include <OISInputManager.h>
+#include <OgreWindowEventUtilities.h>
+
using namespace boost::serialization;
using namespace Engine;
-class InputSystem : public ISystem, public ISingleton<InputSystem>, public OIS::KeyListener, public OIS::MouseListener
+class InputSystem : public ISystem, public ISingleton<InputSystem>, public OIS::KeyListener, public OIS::MouseListener,
+ public Ogre::WindowEventListener
{
private:
size_t mWindowHandle;
@@ -36,6 +39,12 @@ class InputSystem : public ISystem, public ISingleton<InputSystem>, public OIS::
bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id);
bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id);
+ bool windowClosing (Ogre::RenderWindow *rw);
+ void windowMoved (Ogre::RenderWindow *rw);
+ void windowResized (Ogre::RenderWindow *rw);
+ void windowClosed (Ogre::RenderWindow *rw);
+ void windowFocusChanged (Ogre::RenderWindow *rw);
+
public:
InputSystem();
~InputSystem();
View
3  samples/pong-cpp/main.cpp
@@ -24,6 +24,7 @@ class MenuState : public State
READY_TO_ADVANCE();
}
+
void update() {}
string type() { return "MenuState"; }
};
@@ -43,7 +44,7 @@ class GameState : public State
colour(0, 0, 1.0), colour(0, 0, 1.0))->lightHandle()->setDirection(vec3(-1, -1, 0));
World::GetLight("SpotLight")->lightHandle()->setPosition(vec3(300, 300, 0));
- World::MakeObject("ErrorObject");
+ //World::MakeObject("ErrorObject");
}
string type() { return "GameState"; }
View
11 src/Core/GameApplication.cpp
@@ -17,6 +17,7 @@ GameApplication::GameApplication()
mStatsVisible = false;
CONNECT(Engine::Events::KeyEvent, "KeyPressed", &GameApplication::keyPressed);
+ CONNECT2(Events::ClosingEvent, "WindowClosing", &GameApplication::WindowClosing);
}
GameApplication::~GameApplication() { }
@@ -104,9 +105,17 @@ void GameApplication::_shutdown()
mSystemsList.clear();
}
+void GameApplication::WindowClosing(Ogre::RenderWindow *rw, bool &shouldClose)
+{
+ if(shouldClose){
+ LOG("Clicked on [X] -> closing");
+ mRunning = false;
+ }
+}
+
void GameApplication::keyPressed(const OIS::KeyEvent &e)
{
- if (e.key == OIS::KC_ESCAPE) mRunning = false;
+ //if (e.key == OIS::KC_ESCAPE) mRunning = false; //Game wants it
if (e.key == OIS::KC_I)
{
View
6 src/Managers/EventManager.cpp
@@ -32,6 +32,12 @@ void EventManager::fillEventMap()
mSignalAssociation["WindowMouseEntered"] = MouseEnteredEvent();
*/
+ mSignalAssociation["WindowClosing"] = ClosingEvent();
+ mSignalAssociation["WindowMoved"] = WindowEvent();
+ mSignalAssociation["WindowResized"] = WindowEvent();
+ mSignalAssociation["WindowClosed"] = WindowEvent();
+ mSignalAssociation["WindowFocusChanged"] = WindowEvent();
+
mSignalAssociation["Updated"] = GlobalUpdateEvent();
mSignalAssociation["Inited"] = GlobalInitEvent();
}
View
29 src/Systems/InputSystem.cpp
@@ -39,6 +39,33 @@ bool InputSystem::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
return true;
}
+bool InputSystem::windowClosing (Ogre::RenderWindow *rw)
+{
+ bool ret = true;
+ SIGNAL(Events::ClosingEvent, "WindowClosing", rw, ret);
+ return ret;
+}
+
+void InputSystem::windowClosed (Ogre::RenderWindow *rw)
+{
+ SIGNAL(Events::WindowEvent, "WindowClosed", rw);
+}
+
+void InputSystem::windowMoved (Ogre::RenderWindow *rw)
+{
+ SIGNAL(Events::WindowEvent, "WindowMoved", rw);
+}
+
+void InputSystem::windowResized (Ogre::RenderWindow *rw)
+{
+ SIGNAL(Events::WindowEvent, "WindowResized", rw);
+}
+
+void InputSystem::windowFocusChanged (Ogre::RenderWindow *rw)
+{
+ SIGNAL(Events::WindowEvent, "WindowFocusChanged", rw);
+}
+
InputSystem::InputSystem():
mMouse(0),
mKeyboard(0),
@@ -67,6 +94,8 @@ void InputSystem::init()
GraphicSystem::get_const_instance().getWindow()->getCustomAttribute("WINDOW", &mWindowHandle);
LOG("\t- Got window handle from Ogre");
+ Ogre::WindowEventUtilities::addWindowEventListener(GraphicSystem::get_const_instance().getWindow(),this);
+
if( !mInputSystem )
{
OIS::ParamList paramList;
Please sign in to comment.
Something went wrong with that request. Please try again.