Commit 39f8dd37 authored by Gerhard Stein's avatar Gerhard Stein

New overlay for configurable overlay buttons. Still in WIP though

parent 0c00f120
......@@ -347,14 +347,14 @@ void CInput::render()
if(!mpVirtPad)
return;
if(!mpVirtPad->active())
return;
if(mVPadConfigState)
{
mpVirtPad->renderConfig();
return;
}
if(!mpVirtPad->active())
return;
GsWeakSurface blit(gVideoDriver.getBlitSurface());
mpVirtPad->render(blit);
......@@ -678,7 +678,6 @@ void CInput::pollEvents()
if(mpVirtPad && mVPadConfigState)
{
mpVirtPad->processConfig();
return;
}
if(remapper.mappingInput)
......
......@@ -301,9 +301,9 @@ public:
* @brief setInVPadConfigState Want to open the vpad configuration?
* Then open this!
*/
void setInVPadConfigState()
void setInVPadConfigState(const bool value)
{
mVPadConfigState = true;
mVPadConfigState = value;
}
private:
......
......@@ -60,7 +60,7 @@ public:
int immediateIndex = 0;
//int x = 0, y = 0, w = 0, h = 0;
float x = 0.0f, y = 0.0f, w = 0.0f, h = 0.0f;
bool invisible = true;
bool invisible = true;
GsTexture mTexture;
......@@ -137,6 +137,7 @@ public:
virtual void processConfig() = 0;
/**
* @brief renderConfig Render configuration dialog of the dialog
*/
......
......@@ -33,6 +33,21 @@ public:
}
void create(SDL_Renderer* renderer,
Uint32 format,
int access,
int w,
int h)
{
if(mpTexture)
unload();
mpTexture = SDL_CreateTexture(renderer,
format,
access,
w, h);
}
/**
* @brief loadTexture Will try to load the texture
* @param fname filename to load
......@@ -119,6 +134,18 @@ public:
SDL_SetTextureAlphaMod( mpTexture, alpha );
}
/**
* @brief fillRGB Fills the texture with a certain color
* @param renderer
* @param r
* @param g
* @param b
*/
void fillRGB( SDL_Renderer *renderer,
const Uint8 r,
const Uint8 g,
const Uint8 b );
/**
* @brief operator bool For testing the object itself, if the texture is loaded
*/
......
......@@ -157,13 +157,13 @@ bool CGameLauncher::setupMenu()
0.75f ),
GsRect<float>(0.0f, 0.0f, 0.069f, 0.069f) );
/*mLauncherDialog.addControl(new GsButton( "VPad", new OpenVGamePadSettingsEvent(),
mLauncherDialog.addControl(new GsButton( "VPad", new OpenVGamePadSettingsEvent(),
GsControl::Style::NONE,
0.75f,
1.0f,
1.0f ),
GsRect<float>(0.75f, 0.0f, 0.17f, 0.069f) );
*/
mLauncherDialog.addControl(new GsButton( "|", new OpenSettingsMenuEvent(),
GsControl::Style::NONE,
......@@ -646,7 +646,7 @@ void CGameLauncher::pumpEvent(const CEvent *evPtr)
}
else if( dynamic_cast<const OpenVGamePadSettingsEvent*>(evPtr) )
{
gInput.setInVPadConfigState();
gInput.setInVPadConfigState(true);
}
......
This diff is collapsed.
......@@ -4,6 +4,7 @@
#include <base/utils/FindFile.h>
#include <base/CInput.h>
#include <base/GsLogging.h>
#include <graphics/GsTexture.h>
#include <fileio/ResourceMgmt.h>
#include "dpad.h"
......@@ -14,6 +15,7 @@
#include "buttonBg.h"
#include "buttonConfirm.h"
#include "buttonStart.h"
#include "buttonClose.h"
......@@ -77,8 +79,13 @@ bool VirtualKeenControl::init()
/// Load The buttons images
{
// Start with the Background for the gamepad
if(!mPadBackground.loadEmdbeddedPicture(gButtonBgPng, sizeof(gButtonBgPng))) return false;
// Close for configuratin of Virtual pad
if(!mCloseConfigButton.loadEmdbeddedPicture(gButtonClosePng, sizeof(gButtonClosePng))) return false;
GsTexture &tex = mPadConfigBackground.mTexture;
tex.fillRGB( gVideoDriver.Renderer(), 0x0, 0x0, 0x0);
tex.setAlpha(128);
mPadConfigBackground.invisible = true;
// Directional pad
if(!mDPad.loadEmdbeddedPicture(gDPadPng, sizeof(gDPadPng))) return false;
......@@ -116,16 +123,24 @@ bool VirtualKeenControl::ponder()
const float left = 0.025f;
const float right = 0.975f;
if(!mPadBackground.invisible)
if(!mPadConfigBackground.invisible)
{
const GsRect<float> dpadRect(0.0f, 0.75f,
1.0f, 0.25f);
const GsRect<float> dpadRect(0.0f, 0.0f,
1.0f, 1.0f);
mPadConfigBackground.setRect(dpadRect);
}
mPadBackground.setRect(dpadRect);
if(!mCloseConfigButton.invisible)
{
const GsRect<float> dpadRect(0.45f, 0.45f,
0.1f, 0.1f);
mPadBackground.mTexture.setAlpha(uint8_t(255.0f*mTranslucency));
mCloseConfigButton.setRect(dpadRect);
}
if(!mDPad.invisible)
{
const float dpadSize = 0.2f;
......@@ -224,19 +239,59 @@ bool VirtualKeenControl::ponder()
void VirtualKeenControl::processConfig()
{
assert(0);
// Opening section
if(!mConfigOpened)
{
mConfigOpened = true;
mPadConfigBackground.invisible = false;
return;
}
}
void VirtualKeenControl::processCloseConfig(const Vector2D<float> &Pos)
{
// 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))
{
mConfigOpened = false;
mPadConfigBackground.invisible = true;
gInput.setInVPadConfigState(false);
return;
}
}
}
void VirtualKeenControl::renderConfig()
{
assert(0);
//assert(0);
auto addTexture = [](TouchButton &button) -> void
{
button.invisible = false;
if(!button.invisible &&
button.w > 0.0f &&
button.h > 0.0f)
{
gVideoDriver.addTextureRefToRender(button.mTexture, button.Rect());
}
};
mPadConfigBackground.mTexture.setAlpha(127);
addTexture(mPadConfigBackground);
addTexture(mCloseConfigButton);
}
void VirtualKeenControl::hideEverything()
{
mPadBackground.invisible = true;
mPadConfigBackground.invisible = true;
mDPad.invisible = true;
mConfirmButton.invisible = true;
mStartButton.invisible = true;
......@@ -249,7 +304,7 @@ void VirtualKeenControl::hideEverything()
void VirtualKeenControl::hideAllButtons()
{
mPadBackground.invisible = false;
mPadConfigBackground.invisible = false;
mConfirmButton.invisible = true;
mStartButton.invisible = true;
......@@ -276,8 +331,6 @@ void VirtualKeenControl::render(GsWeakSurface &sfc)
}
};
addTexture(mPadBackground);
addTexture(mDPad);
addTexture(mConfirmButton);
......@@ -334,8 +387,9 @@ bool VirtualKeenControl::mouseFingerState(const Vector2D<float> &Pos,
evUp.key.keysym.sym = SDLK_DOWN; SDL_PushEvent(&evUp);*/
/*
if( !mPadBackground.isInside(Pos.x, Pos.y) )
if( !mPadConfigBackground.isInside(Pos.x, Pos.y) )
return false;*/
processCloseConfig(Pos);
bool ok = false;
......@@ -508,7 +562,10 @@ bool VirtualKeenControl::mouseState(const Vector2D<float> &Pos, const bool down)
evUp.key.keysym.sym = SDLK_RIGHT; SDL_PushEvent(&evUp);
evUp.key.keysym.sym = SDLK_DOWN; SDL_PushEvent(&evUp);*/
if( !mPadBackground.isInside(Pos.x, Pos.y) )
processCloseConfig(Pos);
if( mPadConfigBackground.invisible )
return false;
auto bindButtonCommand = [&](const TouchButton &button,
......
......@@ -37,6 +37,12 @@ public:
void processConfig() override;
/**
* @brief processCloseConfig In case the close config button was tapped
* @param Pos
*/
void processCloseConfig(const Vector2D<float> &Pos);
/**
* @brief renderConfig Render configuration dialog of the dialog
*/
......@@ -94,7 +100,7 @@ public:
*/
bool isInside(const Vector2D<float> &Pos) const override
{
return mPadBackground.isInside(Pos.x, Pos.y);
return mPadConfigBackground.isInside(Pos.x, Pos.y);
}
......@@ -111,7 +117,8 @@ public:
#if SDL_VERSION_ATLEAST(2, 0, 0)
TouchButton mPadBackground;
TouchButton mCloseConfigButton;
TouchButton mPadConfigBackground;
TouchButton mDPad;
TouchButton mConfirmButton;
TouchButton mStartButton;
......@@ -126,6 +133,8 @@ public:
#endif
bool mConfigOpened = false;
};
#endif // VGAMEPADSIMPLE_H
......@@ -103,7 +103,6 @@ void CLevelPlay::ponder(const float deltaT)
VirtualKeenControl *vkc = dynamic_cast<VirtualKeenControl*>(gInput.mpVirtPad.get());
assert(vkc);
vkc->hideAllButtons();
vkc->mPadBackground.invisible = false;
vkc->mDPad.invisible = false;
vkc->mJumpButton.invisible = false;
vkc->mPogoButton.invisible = false;
......
......@@ -21,7 +21,6 @@ void CPlayGameVorticon::processInLevel()
VirtualKeenControl *vkc = dynamic_cast<VirtualKeenControl*>(gInput.mpVirtPad.get());
assert(vkc);
vkc->hideAllButtons();
vkc->mPadBackground.invisible = false;
vkc->mDPad.invisible = false;
vkc->mJumpButton.invisible = false;
vkc->mPogoButton.invisible = false;
......
......@@ -42,5 +42,6 @@ int main()
compileBinIntoCharArray("bckgrnd.png","gButtonBgPng", "buttonBg.h");
compileBinIntoCharArray("confirm.png","gButtonConfirmPng", "buttonConfirm.h");
compileBinIntoCharArray("start.png","gButtonStartPng", "buttonStart.h");
compileBinIntoCharArray("closeBtn.png","gButtonClosePng", "buttonClose.h");
return 0;
}
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