Commit edd29180 authored by Gerhard Stein's avatar Gerhard Stein

More checks for the touchbutton config

parent 139eb252
......@@ -201,7 +201,7 @@ bool loadStrFunction(PyObject * pModule,
{
PyObject *objectsRepresentation = PyObject_Repr(pValue);
char *str = PyUnicode_AsUTF8(objectsRepresentation) ;
auto *str = PyUnicode_AsUTF8(objectsRepresentation) ;
if(str)
{
......@@ -265,7 +265,7 @@ bool loadStrFunction(PyObject * pModule,
{
PyObject *objectsRepresentation = PyObject_Repr(pValue);
char *str = PyUnicode_AsUTF8(objectsRepresentation) ;
auto *str = PyUnicode_AsUTF8(objectsRepresentation) ;
if(str)
{
......
......@@ -48,6 +48,12 @@ public:
bool loadEmdbeddedPicture(const unsigned char *data,
const unsigned int size);
/**
* @brief render The actual render function.
* @param dark Should the texture be rendered dark?
*/
void render(const bool dark);
stInputCommand* cmd = nullptr;
......@@ -59,6 +65,7 @@ public:
GsTexture mTexture;
GsTexture mTextureDark;
#if SDL_VERSION_ATLEAST(2, 0, 0)
void clearFingers();
......@@ -80,6 +87,8 @@ public:
#endif
// Happens when user tried to put the button to a different location
bool beingRepositioned = false;
bool mMouseDown = false;
};
......@@ -190,7 +199,6 @@ protected:
//GsSurface mOverlay;
float mTranslucency = 0.5f;
};
......
......@@ -47,6 +47,22 @@ void TouchButton::removeFingerId(const SDL_FingerID fid)
}
}
void TouchButton::render(const bool dark)
{
if(dark)
{
gVideoDriver.addTextureRefToRender(mTextureDark, Rect());
}
else
{
gVideoDriver.addTextureRefToRender(mTexture, Rect());
}
}
// --------------- End of Touch Button -------------------- //
VirtualKeenControl::~VirtualKeenControl()
{}
......@@ -206,7 +222,7 @@ bool VirtualKeenControl::ponder()
mShootButton.setRect(shootRect);
mShootButton.mTexture.setAlpha(uint8_t(255.0f*mTranslucency));
}
}
#endif
......@@ -223,16 +239,18 @@ void VirtualKeenControl::processConfig()
mPadConfigBackground.invisible = false;
return;
}
}
void VirtualKeenControl::processCloseConfig(const Vector2D<float> &Pos)
void VirtualKeenControl::processConfigTouchbuttons(const Vector2D<float> &Pos,
const bool down)
{
// If there is a close button to hit, were are in configuration mode
// and need to close that.
if(!mCloseConfigButton.invisible)
{
// Was it hit?
if(mCloseConfigButton.Rect().HasPoint(Pos))
if(mCloseConfigButton.Rect().HasPoint(Pos) && down)
{
mConfigOpened = false;
mPadConfigBackground.invisible = true;
......@@ -240,13 +258,42 @@ void VirtualKeenControl::processCloseConfig(const Vector2D<float> &Pos)
return;
}
}
auto bindButtonCfg = [&](TouchButton &button) -> bool
{
if(button.invisible)
return false;
if( button.Rect().HasPoint(Pos) )
{
if(mpCurrentButton4Config == nullptr)
{
mpCurrentButton4Config = &button;
}
return true;
}
return false;
};
mpCurrentButton4Config = nullptr;
bindButtonCfg(mDPad);
bindButtonCfg(mConfirmButton);
bindButtonCfg(mStartButton);
bindButtonCfg(mStatusButton);
bindButtonCfg(mShootButton);
bindButtonCfg(mJumpButton);
bindButtonCfg(mPogoButton);
}
void VirtualKeenControl::renderConfig()
{
//assert(0);
auto addTexture = [](TouchButton &button) -> void
{
button.invisible = false;
......@@ -255,7 +302,7 @@ void VirtualKeenControl::renderConfig()
button.w > 0.0f &&
button.h > 0.0f)
{
gVideoDriver.addTextureRefToRender(button.mTexture, button.Rect());
button.render(false);
}
};
......@@ -263,6 +310,22 @@ void VirtualKeenControl::renderConfig()
addTexture(mPadConfigBackground);
addTexture(mCloseConfigButton);
addTexture(mDPad);
addTexture(mConfirmButton);
addTexture(mStartButton);
addTexture(mStatusButton);
addTexture(mShootButton);
addTexture(mJumpButton);
addTexture(mPogoButton);
// If there was a button for config selected
if(mpCurrentButton4Config)
{
addTexture(*mpCurrentButton4Config);
}
}
......@@ -303,16 +366,7 @@ void VirtualKeenControl::render(GsWeakSurface &)
button.w > 0.0f &&
button.h > 0.0f)
{
if(button.hasFingersPressing())
{
gVideoDriver.addTextureRefToRender(button.mTextureDark,
button.Rect());
}
else
{
gVideoDriver.addTextureRefToRender(button.mTexture,
button.Rect());
}
button.render(button.hasFingersPressing());
}
};
......@@ -348,7 +402,7 @@ bool VirtualKeenControl::mouseFingerState(const Vector2D<float> &Pos,
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
processCloseConfig(Pos);
processConfigTouchbuttons(Pos, down);
bool ok = false;
......@@ -499,8 +553,7 @@ bool VirtualKeenControl::mouseState(const Vector2D<float> &Pos, const bool down)
#if SDL_VERSION_ATLEAST(2, 0, 0)
processCloseConfig(Pos);
processConfigTouchbuttons(Pos, down);
if( mPadConfigBackground.invisible )
return false;
......@@ -515,81 +568,88 @@ bool VirtualKeenControl::mouseState(const Vector2D<float> &Pos, const bool down)
if( button.Rect().HasPoint(Pos) )
{
gInput.setCommand(0, cmd, down);
if(mPadConfigBackground.invisible)
{
gInput.setCommand(0, cmd, down);
}
button.mMouseDown = true;
}
};
};
SDL_Event ev;
ev.type = (down ? SDL_KEYDOWN : SDL_KEYUP);
if( !mDPad.invisible &&
mDPad.isInside(Pos.x, Pos.y) )
if(mPadConfigBackground.invisible)
{
// Size of the buttons on the dpad
const float dpadSizePieceW = 0.4f*mDPad.w;
const float dpadSizePieceH = 0.4f*mDPad.h;
// Y-Direction
// Up presses
if(Pos.y<mDPad.y+dpadSizePieceH)
if( !mDPad.invisible &&
mDPad.isInside(Pos.x, Pos.y) )
{
ev.key.keysym.sym = SDLK_UP;
SDL_PushEvent(&ev);
// Size of the buttons on the dpad
const float dpadSizePieceW = 0.4f*mDPad.w;
const float dpadSizePieceH = 0.4f*mDPad.h;
if(down)
// Y-Direction
// Up presses
if(Pos.y<mDPad.y+dpadSizePieceH)
{
SDL_Event evUp;
evUp.type = SDL_KEYUP;
evUp.key.keysym.sym = SDLK_DOWN;
SDL_PushEvent(&evUp);
ev.key.keysym.sym = SDLK_UP;
SDL_PushEvent(&ev);
if(down)
{
SDL_Event evUp;
evUp.type = SDL_KEYUP;
evUp.key.keysym.sym = SDLK_DOWN;
SDL_PushEvent(&evUp);
}
}
}
// Down presses
else if(Pos.y>=mDPad.y+mDPad.h-dpadSizePieceH)
{
ev.key.keysym.sym = SDLK_DOWN;
SDL_PushEvent(&ev);
if(down)
// Down presses
else if(Pos.y>=mDPad.y+mDPad.h-dpadSizePieceH)
{
SDL_Event evUp;
evUp.type = SDL_KEYUP;
evUp.key.keysym.sym = SDLK_UP;
SDL_PushEvent(&evUp);
ev.key.keysym.sym = SDLK_DOWN;
SDL_PushEvent(&ev);
if(down)
{
SDL_Event evUp;
evUp.type = SDL_KEYUP;
evUp.key.keysym.sym = SDLK_UP;
SDL_PushEvent(&evUp);
}
}
}
// X-Direction
// Left presses
if(Pos.x<mDPad.x+dpadSizePieceW)
{
ev.key.keysym.sym = SDLK_LEFT;
SDL_PushEvent(&ev);
if(down)
// X-Direction
// Left presses
if(Pos.x<mDPad.x+dpadSizePieceW)
{
SDL_Event evUp;
evUp.type = SDL_KEYUP;
evUp.key.keysym.sym = SDLK_RIGHT;
SDL_PushEvent(&evUp);
}
ev.key.keysym.sym = SDLK_LEFT;
SDL_PushEvent(&ev);
}
// Right presses
else if(Pos.x>=mDPad.x+mDPad.w-dpadSizePieceW)
{
ev.key.keysym.sym = SDLK_RIGHT;
SDL_PushEvent(&ev);
if(down)
{
SDL_Event evUp;
evUp.type = SDL_KEYUP;
evUp.key.keysym.sym = SDLK_RIGHT;
SDL_PushEvent(&evUp);
}
if(down)
{
SDL_Event evUp;
evUp.type = SDL_KEYUP;
evUp.key.keysym.sym = SDLK_LEFT;
SDL_PushEvent(&evUp);
}
// Right presses
else if(Pos.x>=mDPad.x+mDPad.w-dpadSizePieceW)
{
ev.key.keysym.sym = SDLK_RIGHT;
SDL_PushEvent(&ev);
if(down)
{
SDL_Event evUp;
evUp.type = SDL_KEYUP;
evUp.key.keysym.sym = SDLK_LEFT;
SDL_PushEvent(&evUp);
}
}
}
}
......
......@@ -38,10 +38,10 @@ public:
/**
* @brief processCloseConfig In case the close config button was tapped
* @brief processConfigTouchbuttons In case the close config button was tapped
* @param Pos
*/
void processCloseConfig(const Vector2D<float> &Pos);
void processConfigTouchbuttons(const Vector2D<float> &Pos, const bool down);
/**
* @brief renderConfig Render configuration dialog of the dialog
......@@ -131,6 +131,8 @@ public:
std::set< SDL_FingerID > mFingerSet;
TouchButton *mpCurrentButton4Config = nullptr;
#endif
bool mConfigOpened = false;
......
......@@ -73,7 +73,7 @@ bool CFuse::loadPythonScripts(const std::string &scriptBaseName)
{
PyObject *objectsRepresentation = PyObject_Repr(pValue);
char *str = PyUnicode_AsUTF8(objectsRepresentation) ;
auto *str = PyUnicode_AsUTF8(objectsRepresentation) ;
if(str)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment