Commit 3a8ba181 authored by Gerhard Stein's avatar Gerhard Stein Committed by Gerhard Stein

More OOP with Touchbutton classes

parent 89710137
......@@ -607,11 +607,18 @@ void CInput::transMouseRelCoord(Vector2D<float> &Pos,
}
void CInput::ponder()
{
if(!mpVirtPad)
return;
if(!mpVirtPad->active())
return;
mpVirtPad->ponder();
}
/**
* \brief Called every logic cycle. This triggers the events that occur and process them through various functions
*/
void CInput::pollEvents()
{
// Semaphore
......@@ -1449,20 +1456,6 @@ void CInput::flushEvents()
m_EventList.clear();
}
struct TouchButton
{
stInputCommand* cmd;
int immediateIndex;
int x, y, w, h;
bool invisible;
bool isInside(int _x, int _y) const {
return
x <= _x && _x < x + w &&
y <= _y && _y < y + h;
}
};
static const int w = 480, h = 320;
#define KSHOWHIDECTRLS (-10)
......
......@@ -169,6 +169,9 @@ public:
const SDL_MouseMotionEvent motion,
const GsRect<Uint16> &activeArea);
/**
* @brief Called every logic cycle. This triggers the events that occur and process them through various functions
*/
void pollEvents();
bool getHoldedKey(int key);
......@@ -211,6 +214,8 @@ public:
bool AutoGun(const int player) { return mFullyAutomatic[player]; }
void setAutoGun(const int player, const bool value) { mFullyAutomatic[player] = value; }
void ponder();
/**
* @brief render will render stuff the input want's to get on the screen.
* These are usually overlay where you can touch or click, like virtual gamepads.
......
......@@ -184,6 +184,7 @@ bool GsApp::loadDrivers()
// This function is run every time, the Timer says so, through.
void GsApp::ponder(const float deltaT)
{
gInput.ponder();
pollEvents();
// Process the game control object if no effects are being processed
......
......@@ -5,6 +5,56 @@
#include "graphics/GsTexture.h"
class stInputCommand;
class TouchButton
{
public:
/**
* @brief isInside Is given coordinate inside the button?
*/
bool isInside(const int _x, const int _y) const
{
return
x <= _x && _x < x + w &&
y <= _y && _y < y + h;
}
/**
* @brief setRect set coordinates and dimensions of the loaded texture
* @param rect variable that does that
*/
auto setRect(const GsRect<float> &rect) -> void
{
this->x = rect.x; this->y = rect.y;
this->w = rect.w; this->h = rect.h;
}
auto Rect() const -> auto
{
return GsRect<float>(this->x, this->y,
this->w, this->h);
}
/**
* @brief loadPicture load the button-picture from a given file
* @param picFile file to load
*/
bool loadPicture(const std::string &picFile);
stInputCommand* cmd = nullptr;
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 = false;
GsTexture mTexture;
};
/**
* @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.
......@@ -24,6 +74,8 @@ public:
mTranslucency(0.5f) {}
virtual ~GsVirtualInput() {}
/**
* @brief active
* @return tells wheter Virtual Input is enabled.
......@@ -39,6 +91,12 @@ public:
*/
virtual bool init() = 0;
/**
* @brief ponder Performs some logic like transformations.
* @return
*/
virtual bool ponder() = 0;
/**
* @brief render is called when it's time to render this object
* @param sfc Reference to surface on which it can be rendered.
......
......@@ -114,6 +114,7 @@ bool CSDLVideo::resizeDisplayScreen(const GsRect<Uint16>& newDim)
if(renderer != nullptr)
{
SDL_RenderSetLogicalSize(renderer, mActiveAreaRect.w, mActiveAreaRect.h);
SDL_RenderSetViewport(renderer, nullptr);
}
#else
mDisplaySfc.setPtr(SDL_SetVideoMode( mActiceAreaRect.w, mActiceAreaRect.h, 32, m_Mode ));
......@@ -188,6 +189,26 @@ void CSDLVideo::hackIt() {} // Empty
#endif
/**
* @brief tilt tilt the rect 90 degree clockwise
* @param dpadRect rect to rotate
* @param rotPt point of rotation
* @return The rotated rect
*/
GsRect<int> tilt(const GsRect<int> &dpadRect,
const Vector2D<int> &rotPt)
{
const int x1_rel = dpadRect.x-rotPt.x;
const int y1_rel = dpadRect.y-rotPt.y;
const int x2_rel = -y1_rel;
const int y2_rel = x1_rel;
return GsRect<int>( x2_rel+rotPt.x,
y2_rel+rotPt.y,
dpadRect.h,
dpadRect.w);
}
void CSDLVideo::transformScreenToDisplay()
{
......@@ -196,6 +217,8 @@ void CSDLVideo::transformScreenToDisplay()
const bool tiltVideo = m_VidConfig.mTiltedScreen;
const auto &finalWindowSize = m_VidConfig.mDisplayRect;
mpScreenSfc->lock();
SDL_UpdateTexture(mpSDLScreenTexture.get(),
nullptr,
......@@ -219,18 +242,11 @@ void CSDLVideo::transformScreenToDisplay()
{
if(tiltVideo)
{
/*
SDL_Point pt;
pt.x = mActiveAreaRect.w/2;
pt.y = mActiveAreaRect.h/2;*/
SDL_RenderCopyEx(local_renderer,
local_texture,
local_srcrect,
local_dstrect,
90.0,
//&pt,
nullptr,
SDL_FLIP_NONE);
}
......@@ -243,7 +259,7 @@ void CSDLVideo::transformScreenToDisplay()
}
};
SDL_RenderClear(renderer);
SDL_RenderClear(renderer);
RenderCopy(renderer, mpSDLScreenTexture.get(), nullptr, nullptr);
......@@ -258,6 +274,9 @@ void CSDLVideo::transformScreenToDisplay()
const GsRect<Uint16> &src = std::get<1>(triple);
const GsRect<Uint16> &dst = std::get<2>(triple);
// TODO: Tilt here!
if(src.empty())
{
if(dst.empty())
......@@ -267,7 +286,14 @@ void CSDLVideo::transformScreenToDisplay()
else
{
SDL_Rect dstSDL = dst.SDLRect();
RenderCopy(renderer, texture, nullptr, &dstSDL);
// Transfrom the coordinates for the final screen.
/*dstSDL.y = (dstSDL.y*finalWindowSize.h)/mActiveAreaRect.h;
dstSDL.x = (dstSDL.x*finalWindowSize.x)/mActiveAreaRect.w;
RenderCopy(renderer, texture, nullptr, &dstSDL);*/
}
}
else
......
......@@ -36,6 +36,26 @@ CVideoDriver::~CVideoDriver()
}
void CVideoDriver::addTextureRefToRender(GsTexture& textureRef, const GsRect<float> &dstRect)
{
const GsRect<Uint16> clickGameArea = mpVideoEngine->getActiveAreaRect();
const auto dpadX = Uint16(float(clickGameArea.w) * dstRect.x);
const auto dpadY = Uint16(float(clickGameArea.h) * dstRect.y);
const auto dpadWidth = Uint16(float(clickGameArea.w) * dstRect.w);
const auto dpadHeight = Uint16(float(clickGameArea.h) * dstRect.h);
const GsRect<Uint16> dpadRect(dpadX, dpadY,
dpadWidth, dpadHeight);
std::tuple< GsTexture&, const GsRect<Uint16>, const GsRect<Uint16> >
triple( textureRef, {0, 0, 0, 0}, dpadRect );
mpVideoEngine->mRenderTexturePtrs.push(triple);
}
bool CVideoDriver::init()
{
mVidConfig.reset();
......
......@@ -194,13 +194,7 @@ public:
* @param textureRef pointer to the SDL Texture
* @param dstRect Rect where to put this texture on
*/
void addTextureRefToRender(GsTexture& textureRef, const GsRect<Uint16> &dstRect)
{
std::tuple< GsTexture&, const GsRect<Uint16>, const GsRect<Uint16> >
triple( textureRef, {0, 0, 0, 0}, dstRect );
mpVideoEngine->mRenderTexturePtrs.push(triple);
}
void addTextureRefToRender(GsTexture& textureRef, const GsRect<float> &dstRect);
#endif
......
......@@ -150,7 +150,8 @@ bool CVideoEngine::init()
return true;
}
void CVideoEngine::updateAspectRect(const GsRect<Uint16>& displayRes, const int aspWidth, const int aspHeight)
void CVideoEngine::updateAspectRect(const GsRect<Uint16>& displayRes,
const int aspWidth, const int aspHeight)
{
if (aspWidth == 0 || aspHeight == 0)
{
......
......@@ -7,36 +7,32 @@ class VirtualKeenControl : public GsVirtualInput
{
public:
virtual ~VirtualKeenControl();
// OK => Only show Ok Button
// WMAP => Shows Enter Button for the world map and another one for the item box and one for the main menu
// ACTION => Shows the three action button for jumping, pogo and fire as well as the item box button and the main menu button
enum BUTTON_MODE
{
OK = 0,
WMAP = 1,
ACTION = 2
};
enum class BUTTON_MODE
{ OK, WMAP, ACTION };
/**
* @brief VirtualKeenControl Will initialize
* @brief init initialize the object
* @return true if everything went right, otherwise false.
*/
VirtualKeenControl() :
mShowDPad(true),
mHideStartButton(false),
mButtonMode(OK) {}
bool init() override;
/**
* @brief init initialize the object
* @return true if everything went right, otherwise false.
* @brief ponder Performs some logic like transformations
* @return
*/
bool init();
bool ponder() override;
/**
* @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);
void render(GsWeakSurface &sfc) override;
/**
* @brief mouseState Mouse state processing. Since the up and down code are similar,
......@@ -50,7 +46,7 @@ public:
* @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)
void mouseDown(const Vector2D<float> &Pos) override
{
mouseState(Pos, true);
}
......@@ -59,29 +55,38 @@ public:
* @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)
void mouseUp(const Vector2D<float> &Pos) override
{
mouseState(Pos, false);
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
GsTexture mDPadTexture;
GsTexture mConfirmButtonTexture;
GsTexture mStartButtonTexture;
//GsTexture mDPadTexture;
//GsTexture mConfirmButtonTexture;
//GsTexture mStartButtonTexture;
TouchButton mDPad;
TouchButton mConfirmButton;
TouchButton mStartButton;
// Control buttons
GsTexture mJumpButtonTexture;
GsTexture mShootButtonTexture;
GsTexture mPogoButtonTexture;
GsTexture mStatusButtonTexture;
//GsTexture mJumpButtonTexture;
//GsTexture mShootButtonTexture;
//GsTexture mPogoButtonTexture;
//GsTexture mStatusButtonTexture;
TouchButton mJumpButton;
TouchButton mShootButton;
TouchButton mPogoButton;
TouchButton mStatusButton;
#endif
bool mShowDPad;
bool mHideStartButton;
bool mShowStatusButton = false;
bool mHideStartButton = false;
BUTTON_MODE mButtonMode;
BUTTON_MODE mButtonMode = BUTTON_MODE::OK;
};
#endif // VGAMEPADSIMPLE_H
......@@ -35,7 +35,7 @@ GameMenu(GsRect<float>(0.15f, 0.20f, 0.65f, 0.55f), style )
mpMenuDialog->addControl( mpShowCursorSwitch );
mpTiltScreenSwitch = new Switch("TiltedScreen", style);
//mpMenuDialog->addControl( mpTiltScreenSwitch );
mpMenuDialog->addControl( mpTiltScreenSwitch );
// Create the fps config selection control
std::list<std::string> List;
......
......@@ -129,7 +129,7 @@ bool CPassiveGalaxy::init()
VirtualKeenControl *vkc = dynamic_cast<VirtualKeenControl*>(gInput.mpVirtPad.get());
assert(vkc);
vkc->mShowDPad = false;
vkc->mDPad.invisible = true;
const auto &storyText = gBehaviorEngine.getString("STORY_TEXT");
mStoryTextVector = explode(storyText, "\n");
......@@ -370,7 +370,7 @@ void CPassiveGalaxy::processTitle()
VirtualKeenControl *vkc = dynamic_cast<VirtualKeenControl*>(gInput.mpVirtPad.get());
assert(vkc);
vkc->mShowDPad = true;
vkc->mDPad.invisible = false;
gEventManager.add(new OpenMainMenuEvent());
mSkipSection = false;
......@@ -468,7 +468,7 @@ void CPassiveGalaxy::processStarWars()
VirtualKeenControl *vkc = dynamic_cast<VirtualKeenControl*>(gInput.mpVirtPad.get());
assert(vkc);
vkc->mShowDPad = true;
vkc->mDPad.invisible = false;
gEventManager.add(new OpenMainMenuEvent());
mSkipSection = false;
......
......@@ -712,7 +712,7 @@ void CPlayGameGalaxy::processInput()
}
assert(vkc);
vkc->mShowDPad = true;
vkc->mDPad.invisible = false;
}
......
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