also render input system with some nice overlay, added also some keys (F3 and special show/hide controls key)

This commit is contained in:
Albert Zeyer
2009-11-17 18:42:33 +01:00
parent 80cf1257c7
commit 3d8ea00f31
3 changed files with 95 additions and 14 deletions

View File

@@ -157,7 +157,14 @@ bool CInput::readNewEvent(Uint8 device, int position)
{
switch ( Event.type )
{
case SDL_KEYDOWN:
case SDL_QUIT:
g_pLogFile->textOut("SDL: Got quit event in readNewEvent!");
#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR)
// on iPhone, we just want to quit in this case
exit(0);
#endif
break;
case SDL_KEYDOWN:
InputCommand[device][position].keysym = Event.key.keysym.sym;
return true;
break;
@@ -204,7 +211,11 @@ void CInput::pollEvents()
case SDL_QUIT:
g_pLogFile->textOut("SDL: Got quit event!");
m_exit = true;
break;
#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR)
// on iPhone, we just want to quit in this case
exit(0);
#endif
break;
case SDL_KEYDOWN:
processKeys(1);
break;
@@ -543,6 +554,8 @@ struct TouchButton {
static const int w = 320, h = 200;
#define KSHOWHIDECTRLS (-10)
static TouchButton* getPhoneButtons(stInputCommand InputCommand[NUM_INPUTS][NUMBER_OF_COMMANDS]) {
static const int middlex = w / 2;
static const int middley = h / 2;
@@ -557,16 +570,19 @@ static TouchButton* getPhoneButtons(stInputCommand InputCommand[NUM_INPUTS][NUMB
{ &InputCommand[0][IC_POGO], -1, middlex + w / 6, middley, w / 6, h / 2},
{ &InputCommand[0][IC_FIRE], KSPACE, middlex + w / 3, middley, w / 6, h / 2},
{ &InputCommand[0][IC_STATUS], KENTER, 0, 0, w, h}
{ &InputCommand[0][IC_STATUS], KENTER, 0, 0, w/2, h/4},
{ NULL, KQUIT, 5*w/6, 0, w/6, h/6},
{ NULL, KSHOWHIDECTRLS, 4*w/6, 0, w/6, h/6},
{ NULL, KF3 /* save dialog, see gamedo_HandleFKeys */, 3*w/6, 0, w/6, h/6},
};
return phoneButtons;
}
static const int phoneButtonN = 8;
static const int phoneButtonN = 11;
static Uint32 phoneButtonLasttime[phoneButtonN] = {0,0,0,0,0,0,0,0};
static int phoneButton_MouseIndex[phoneButtonN] = {-1,-1,-1,-1,-1,-1,-1,-1};
static Uint32 phoneButtonLasttime[phoneButtonN] = {0,0,0,0,0,0,0,0,0,0,0};
static int phoneButton_MouseIndex[phoneButtonN] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
@@ -581,13 +597,13 @@ static TouchButton* getPhoneButton(int x, int y, TouchButton phoneButtons[]) {
void CInput::processMouse() {
TouchButton* phoneButtons = getPhoneButtons(InputCommand);
Uint32 curTime = SDL_GetTicks();
for(int i = 0; i < phoneButtonN; ++i) {
bool down = phoneButton_MouseIndex[i] >= 0;
TouchButton& b = phoneButtons[i];
b.cmd->active = down;
if(b.cmd)
b.cmd->active = down;
// handle immediate keys
if(b.immediateIndex >= 0)
@@ -622,7 +638,7 @@ void CInput::processMouse(int x, int y, bool down, int index) {
phoneButton_MouseIndex[i] = down ? index : -1;
if(!down) {
if(b.cmd->active) {
if(b.cmd && b.cmd->active) {
//if(phoneButton_MouseIndex[i] != index)
// break;
}
@@ -634,6 +650,67 @@ void CInput::processMouse(int x, int y, bool down, int index) {
}
#ifdef USE_OPENGL
static void drawButton(TouchButton& button, bool down) {
// similar mysterious constant as in renderTexture
glViewport(0,255,w,h);
int crop = 2;
float x1 = float(button.x + crop) / w;
float x2 = float(button.x+button.w - crop) / w;
float y1 = float(button.y + crop) / h;
float y2 = float(button.y+button.h - crop) / h;
GLfloat vertices[] =
{
x1, y1,
x2, y1,
x2, y2,
x1, y2,
};
//Render the vertices by pointing to the arrays.
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vertices);
if(down)
glColor4f(0,0,0, 0.5);
else
glColor4f(0,0,0, 0.2);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
//Finally draw the arrays.
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
}
#endif
void CInput::renderOverlay() {
#ifdef USE_OPENGL // only ogl supported yet (and probably worth)
#if defined(MOUSEWRAPPER)
static bool showControls = true;
static bool buttonShowHideCtrlWasDown = false;
TouchButton* phoneButtons = getPhoneButtons(InputCommand);
for(int i = phoneButtonN - 1; i >= 0; --i) {
TouchButton& b = phoneButtons[i];
bool down = phoneButton_MouseIndex[i] >= 0;
if(showControls) drawButton(b, down);
if(b.immediateIndex == KSHOWHIDECTRLS) {
if(buttonShowHideCtrlWasDown && !down)
showControls = !showControls;
buttonShowHideCtrlWasDown = down;
}
}
#endif
#endif
}
#ifdef WIZ
void CInput::WIZ_EmuKeyboard( int button, int value )

View File

@@ -171,6 +171,8 @@ public:
void flushCommands(void);
void flushAll(void);
void renderOverlay(); // for mouse wrapper gfx or other stuff
private:
SDL_Event Event;
stInputCommand InputCommand[NUM_INPUTS][NUMBER_OF_COMMANDS];

View File

@@ -7,6 +7,7 @@
#include "COpenGL.h"
#include "CVideoDriver.h"
#include "../CLogFile.h"
#include "CInput.h" // for CInput::renderOverlay
#define GAME_STD_WIDTH 320
#define GAME_STD_HEIGHT 200
@@ -164,11 +165,12 @@ static void renderTexture(GLuint texture, bool withAlpha = false) {
glEnable(GL_BLEND);
if(withAlpha)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
else
glBlendFunc(GL_ONE, GL_ZERO /*GL_SRC_COLOR*/);
glBindTexture (GL_TEXTURE_2D, texture);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
// Set the texture parameters to use a linear filter when minifying.
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -183,9 +185,7 @@ static void renderTexture(GLuint texture, bool withAlpha = false) {
}
void COpenGL::render(bool withFG)
{
//glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
{
renderTexture(m_texBG);
LockSurface(m_blitsurface);
@@ -225,5 +225,7 @@ void COpenGL::render(bool withFG)
if(withFG)
renderTexture(m_texFG, true);
g_pInput->renderOverlay();
SDL_GL_SwapBuffers();
}