Skip to content

Commit

Permalink
Now multiple input overlays can be used depending on the situation of
Browse files Browse the repository at this point in the history
the gameplay.
  • Loading branch information
gerstrong committed Dec 20, 2014
1 parent 20d0b4d commit 41c3cb0
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 170 deletions.
19 changes: 10 additions & 9 deletions lib/GsKit/base/CInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ CInput::CInput()

//Create the semaphor
pollSem = SDL_CreateSemaphore(1);

mVirtualInput.init();
}

/**
Expand Down Expand Up @@ -331,11 +329,14 @@ std::string CInput::getEventShortName(int command, unsigned char input)

void CInput::render()
{
if(!mVirtualInput.active())
if(!mpVirtPad)
return;

if(!mpVirtPad->active())
return;

GsWeakSurface blit(gVideoDriver.getBlitSurface());
mVirtualInput.render(blit);
mpVirtPad->render(blit);
}


Expand Down Expand Up @@ -648,12 +649,12 @@ void CInput::pollEvents()
case SDL_MOUSEBUTTONDOWN:

// If Virtual gamepad takes control...
if(mVirtualInput.active())
{
if(mpVirtPad && mpVirtPad->active())
{
if(Event.button.button <= 3)
{
transMouseRelCoord(Pos, Event.motion, clickGameArea);
mVirtualInput.mouseDown(Pos);
mpVirtPad->mouseDown(Pos);
}
}
else
Expand All @@ -678,10 +679,10 @@ void CInput::pollEvents()
break;

case SDL_MOUSEBUTTONUP:
if(mVirtualInput.active())
if(mpVirtPad && mpVirtPad->active())
{
transMouseRelCoord(Pos, Event.motion, clickGameArea);
mVirtualInput.mouseUp(Pos);
mpVirtPad->mouseUp(Pos);
}
else
{
Expand Down
7 changes: 3 additions & 4 deletions lib/GsKit/base/CInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,15 @@ class CInput : public GsSingleton<CInput>
*/
void pushBackButtonEventExtEng();

private:
// One virtual input overlay can be active be processed. This is useful for game to ported on mobile devices
std::unique_ptr<GsVirtualInput> mpVirtPad;

// Class for overlays when a virtual gamepad or keyboard is needed. For example on mobiles devices
GsVirtualInput mVirtualInput;
private:

// Input Events
CEventContainer m_EventList;



// SDL_Event Vector
//
/**
Expand Down
131 changes: 0 additions & 131 deletions lib/GsKit/base/GsVirtualinput.cpp

This file was deleted.

37 changes: 12 additions & 25 deletions lib/GsKit/base/GsVirtualinput.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@
#include "graphics/GsTexture.h"


// TODO: Virtual Pad Base Class which in which the derived is managed by the launched game itself.
// GsVirtualInput should only get a shared pointer to that derived class which can be exchanged at anytime.

/*enum VPadMode
{
VPADMODE_MENU,
VPADMODE_WORLDMAP, // Show buttons
VPADMODE_GAMEPLAY
};*/


/**
* @brief The GsVirtualInput class represents input devices which might be absent yet required for the program
* to run. For example Commander Genius as of Commander Keen need Keyboard or Joystick in general.
Expand All @@ -27,7 +16,13 @@
class GsVirtualInput
{
public:
GsVirtualInput();
/**
* @brief GsVirtualInput basic constructor, just setup some variables.
*/
GsVirtualInput() :
mEnabled(true),
mTranslucency(0.5f) {}


/**
* @brief active
Expand All @@ -42,35 +37,27 @@ class GsVirtualInput
* @brief init initialize the object
* @return true if everything went right, otherwise false.
*/
bool init();
virtual bool init() = 0;

/**
* @brief render is called when it's time to render this object
* @param sfc Reference to surface on which it can be rendered.
*/
void render(GsWeakSurface &sfc);

/**
* @brief mouseState Mouse state processing. Since the up and down code are similar,
* they are just redirected here with the down state
* @param Pos Position
* @param down true if event indicates mouse button down, otherwise up
*/
void mouseState(const Vector2D<float> &Pos, const bool down);
virtual void render(GsWeakSurface &sfc) = 0;

/**
* @brief mouseDown Mouse down event when sent when touch event triggered or mouse sends that.
* @param Pos Position of the mouse event
*/
void mouseDown(const Vector2D<float> &Pos);
virtual void mouseDown(const Vector2D<float> &Pos) = 0;

/**
* @brief mouseDown Mouse Up event when sent when touch event triggered or mouse sends that.
* @param Pos Position of the mouse event
*/
void mouseUp(const Vector2D<float> &Pos);
virtual void mouseUp(const Vector2D<float> &Pos) = 0;

private:
protected:

bool mEnabled;

Expand Down
3 changes: 2 additions & 1 deletion lib/GsKit/base/video/CSDLVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ void CSDLVideo::transformScreenToDisplay()
{
auto &triple = mRenderTexturePtrs.front();

SDL_Texture *texture = (std::get<0>(triple)).getPtr();
GsTexture &gsTexture = std::get<0>(triple);
SDL_Texture *texture = gsTexture.getPtr();
const GsRect<Uint16> &src = std::get<1>(triple);
const GsRect<Uint16> &dst = std::get<2>(triple);

Expand Down
Loading

0 comments on commit 41c3cb0

Please sign in to comment.