Skip to content

Commit

Permalink
Add mouseInput initiating and print it (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
akindyakov committed Sep 1, 2013
1 parent 56771b1 commit 89d6f1b
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 41 deletions.
2 changes: 1 addition & 1 deletion modules/heliumGameCore/include/heliumGameCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class HeliumGameCore : public HeliumGameCoreObjects {

protected:
KeyboardUserInput* keyboardInput;
// MouseUserInput* mouseInput;
MouseUserInput* mouseInput;
};

#endif // HELIUM_GAME_CORE_INCLUDED
Expand Down
5 changes: 4 additions & 1 deletion modules/heliumGameCore/src/heliumGameCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ namespace P = Polycode;

HeliumGameCore::HeliumGameCore( Polycode::Core* engCore )
: HeliumGameCoreObjects( engCore ),
keyboardInput(new KeyboardUserInput(this))
keyboardInput(new KeyboardUserInput()),
mouseInput(new MouseUserInput())
{

}
Expand All @@ -27,13 +28,15 @@ HeliumGameCore::~HeliumGameCore() {
void HeliumGameCore::game() {
HeliumGlobal::setCurrentGame(this);
keyboardInput->setEnable(true);
mouseInput->setEnable(true);

bool game_is_running = true;
while( game_is_running ) {
game_is_running = engineCore->Update();
objectWorld.lifeStep();
engineCore->Render();
}
mouseInput->setEnable(false);
keyboardInput->setEnable(false);
HeliumGlobal::setCurrentGame(NULL);
return;
Expand Down
2 changes: 2 additions & 0 deletions modules/heliumScreenObjects/include/heliumScreenObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class ScreenObjectsWorld {
void addAlifeObject( AlifeScreenObject* );

void lifeStep();
bool mouseLeftClick(Polycode::Vector2 position);
bool mouseRightClick(Polycode::Vector2 position);

void setPause(bool);
bool getPause();
Expand Down
8 changes: 8 additions & 0 deletions modules/heliumScreenObjects/src/heliumScreenObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ void ScreenObjectsWorld::lifeStep() {
(*it)->lifeStep();
}
}

bool ScreenObjectsWorld::mouseLeftClick(Polycode::Vector2 position) {

}

bool ScreenObjectsWorld::mouseRightClick(Polycode::Vector2 position) {

}

void ScreenObjectsWorld::setPause(bool set) {
engineScreen->enabled = set;
Expand Down
12 changes: 6 additions & 6 deletions modules/userInput/include/heliumInputDipather.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

class KeyboardUserInput : public Polycode::EventHandler {
public:
KeyboardUserInput(HeliumGameCoreObjects*);
KeyboardUserInput();
virtual ~KeyboardUserInput();

void handleEvent(Polycode::Event*);
Expand All @@ -36,7 +36,7 @@ class KeyboardUserInput : public Polycode::EventHandler {
class MouseButtonUserInput : public Polycode::EventHandler {
public:
MouseButtonUserInput();
virtual ~MouseButtonUserInput();
virtual ~MouseButtonUserInput() {}

void handleEvent(Polycode::Event*);

Expand All @@ -57,7 +57,7 @@ class MouseButtonUserInput : public Polycode::EventHandler {
class MouseMoveUserInput : public Polycode::EventHandler {
public:
MouseMoveUserInput();
virtual ~MouseMoveUserInput();
virtual ~MouseMoveUserInput() {}

void handleEvent(Polycode::Event*){};
// not KeyHandler
Expand All @@ -71,7 +71,7 @@ class MouseMoveUserInput : public Polycode::EventHandler {
class MouseOtherUserInput : public Polycode::EventHandler {
public:
MouseOtherUserInput();
virtual ~MouseOtherUserInput();
virtual ~MouseOtherUserInput(){}

void handleEvent(Polycode::Event*){}
// not KeyHandler
Expand All @@ -82,7 +82,7 @@ class MouseOtherUserInput : public Polycode::EventHandler {
class MouseWheelUserInput : public Polycode::EventHandler {
public:
MouseWheelUserInput();
~MouseWheelUserInput();
~MouseWheelUserInput(){}

void handleEvent(Polycode::Event*);
void addUpEventHandler(KeyHandler*);
Expand All @@ -96,7 +96,7 @@ class MouseWheelUserInput : public Polycode::EventHandler {

class MouseUserInput : public Polycode::EventHandler {
public:
MouseUserInput(HeliumGameCoreObjects*);
MouseUserInput();
virtual ~MouseUserInput();

void addEventHandler(Polycode::PolyKEY, KeyHandler*);
Expand Down
84 changes: 51 additions & 33 deletions modules/userInput/src/heliumInputDipather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
* Author: AKindyakov
* ========================================================
*/

#include <iostream>
#include <Polycode.h>

#include "heliumInputDipather.h"
#include "heliumGameGlobal.h"

namespace P = Polycode;

KeyboardUserInput::KeyboardUserInput(HeliumGameCoreObjects* gm) {
KeyboardUserInput::KeyboardUserInput() {
handlers[P::KEY_ESCAPE] = new EscapeGame();
handlers[P::KEY_PAUSE] = new PauseGame();
}
Expand Down Expand Up @@ -65,17 +65,24 @@ void KeyboardUserInput::keyUP(P::InputEvent* inputEvent){
void KeyboardUserInput::keyDOWN(P::InputEvent* inputEvent){
}

MouseUserInput::MouseUserInput(HeliumGameCoreObjects*) {
}
MouseUserInput::MouseUserInput()
: buttoninput(new MouseButtonUserInput),
moveInput (new MouseMoveUserInput ),
otherInput (new MouseOtherUserInput),
wheelInput (new MouseWheelUserInput)
{}

MouseUserInput::~MouseUserInput() {
}

void MouseUserInput::setEnable(bool set) {
buttoninput->setEnable(set);
moveInput->setEnable(set);
otherInput->setEnable(set);
wheelInput->setEnable(set);
// moveInput->setEnable(set);
// otherInput->setEnable(set);
// wheelInput->setEnable(set);
}

MouseButtonUserInput::MouseButtonUserInput () {
}

void MouseButtonUserInput::setEnable(bool set) {
Expand All @@ -96,32 +103,34 @@ void MouseButtonUserInput::setEnable(bool set) {
void MouseButtonUserInput::handleEvent(Polycode::Event* e) {
P::InputEvent* ie = dynamic_cast<P::InputEvent*>(e);
int code = ie->mouseButton;
switch(e->getEventCode()) {
case P::InputEvent::EVENT_MOUSEDOWN:
{
std::map<int, MouseKeyHandler*>::iterator prc = downHandlers.find(code);
if ( prc != downHandlers.end() ) {
prc->second->process(ie->getMousePosition());
}
}
break;
case P::InputEvent::EVENT_MOUSEUP:
{
std::map<int, MouseKeyHandler*>::iterator prc = upHandlers.find(code);
if ( prc != upHandlers.end() ) {
prc->second->process(ie->getMousePosition());
}
}
break;
case P::InputEvent::EVENT_DOUBLECLICK:
{
std::map<int, MouseKeyHandler*>::iterator prc = doubleClickHandlers.find(code);
if ( prc != doubleClickHandlers.end() ) {
prc->second->process(ie->getMousePosition());
}
}
break;
}
std::cout << "Mouse input: " << code << '\n';
// switch(e->getEventCode()) {
// case P::InputEvent::EVENT_MOUSEDOWN:
// {
// std::map<int, MouseKeyHandler*>::iterator prc = downHandlers.find(code);
// if ( prc != downHandlers.end() ) {
// prc->second->process(ie->getMousePosition());
// }
// }
// break;
// case P::InputEvent::EVENT_MOUSEUP:
// {
// std::map<int, MouseKeyHandler*>::iterator prc = upHandlers.find(code);
// if ( prc != upHandlers.end() ) {
// prc->second->process(ie->getMousePosition());
// }
// HeliumGlobal::GetCurrentGame()->getSceneWorldPt():E
// }
// break;
// case P::InputEvent::EVENT_DOUBLECLICK:
// {
// std::map<int, MouseKeyHandler*>::iterator prc = doubleClickHandlers.find(code);
// if ( prc != doubleClickHandlers.end() ) {
// prc->second->process(ie->getMousePosition());
// }
// }
// break;
// }
}

void MouseButtonUserInput::addRightEventHandler(MouseKeyHandler*) {
Expand All @@ -133,6 +142,9 @@ void MouseButtonUserInput::addLeftEventHandler(MouseKeyHandler*) {
void MouseButtonUserInput::addButtonEventHandler(int, MouseKeyHandler*) {
}

MouseMoveUserInput::MouseMoveUserInput() {
}

void MouseMoveUserInput::setEnable(bool set) {
HeliumGameCore* gm = HeliumGlobal::getCurrentGame();
Polycode::CoreInput* input = gm->getEngineCorePt()->getInput();
Expand All @@ -144,6 +156,9 @@ void MouseMoveUserInput::setEnable(bool set) {
}
}

MouseOtherUserInput::MouseOtherUserInput () {
}

void MouseOtherUserInput::setEnable(bool set) {
HeliumGameCore* gm = HeliumGlobal::getCurrentGame();
Polycode::CoreInput* input = gm->getEngineCorePt()->getInput();
Expand All @@ -159,6 +174,9 @@ void MouseOtherUserInput::setEnable(bool set) {
}
}

MouseWheelUserInput::MouseWheelUserInput () {
}

void MouseWheelUserInput::setEnable(bool set) {
HeliumGameCore* gm = HeliumGlobal::getCurrentGame();
Polycode::CoreInput* input = gm->getEngineCorePt()->getInput();
Expand Down

0 comments on commit 89d6f1b

Please sign in to comment.