Fix keyboard input on Blackberry and enable on Qt frontend. Make Qt open a window instead of fullscreen for non-mobile systems. Make the window resizable (updates pixel_*res and dp_*res).
This commit is contained in:
parent
e01acb48da
commit
472cf6af1a
3 changed files with 83 additions and 4 deletions
|
@ -116,7 +116,6 @@ const int buttonMappings[18] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
void SimulateGamepad(InputState *input) {
|
void SimulateGamepad(InputState *input) {
|
||||||
input->pad_buttons = 0;
|
|
||||||
input->pad_lstick_x = 0;
|
input->pad_lstick_x = 0;
|
||||||
input->pad_lstick_y = 0;
|
input->pad_lstick_y = 0;
|
||||||
input->pad_rstick_x = 0;
|
input->pad_rstick_x = 0;
|
||||||
|
@ -444,6 +443,12 @@ int main(int argc, char *argv[]) {
|
||||||
input_state.pad_buttons |= (1<<b);
|
input_state.pad_buttons |= (1<<b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
for (int b = 0; b < 14; b++) {
|
||||||
|
if (value == buttonMappings[b])
|
||||||
|
input_state.pad_buttons &= ~(1<<b);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (domain == navigator_get_domain()) {
|
} else if (domain == navigator_get_domain()) {
|
||||||
|
|
|
@ -20,15 +20,32 @@ void LaunchBrowser(const char *url)
|
||||||
QDesktopServices::openUrl(QUrl(url));
|
QDesktopServices::openUrl(QUrl(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SimulateGamepad(InputState *input) {
|
||||||
|
input->pad_lstick_x = 0;
|
||||||
|
input->pad_lstick_y = 0;
|
||||||
|
input->pad_rstick_x = 0;
|
||||||
|
input->pad_rstick_y = 0;
|
||||||
|
|
||||||
|
if (input->pad_buttons | (1<<14))
|
||||||
|
input->pad_lstick_y=1;
|
||||||
|
else if (input->pad_buttons | (1<<15))
|
||||||
|
input->pad_lstick_y=-1;
|
||||||
|
if (input->pad_buttons | (1<<16))
|
||||||
|
input->pad_lstick_x=-1;
|
||||||
|
else if (input->pad_buttons | (1<<17))
|
||||||
|
input->pad_lstick_x=1;
|
||||||
|
}
|
||||||
|
|
||||||
float CalculateDPIScale()
|
float CalculateDPIScale()
|
||||||
{
|
{
|
||||||
// Calculate DPI from TWIPS on Symbian
|
// Calculate DPI from TWIPS on Symbian
|
||||||
#ifdef __SYMBIAN32__
|
#ifdef __SYMBIAN32__
|
||||||
TSize sizeTwips = CEikonEnv::Static()->ScreenDevice()->SizeInTwips();
|
TSize sTwips = CEikonEnv::Static()->ScreenDevice()->SizeInTwips();
|
||||||
float dpi = sqrt((float)(pixel_xres*pixel_xres + pixel_yres*pixel_yres))
|
float dpi = sqrt((float)(pixel_xres*pixel_xres + pixel_yres*pixel_yres))
|
||||||
/ (sqrt((float)(sizeTwips.iHeight*sizeTwips.iHeight + sizeTwips.iWidth*sizeTwips.iWidth)) / KTwipsPerInch);
|
/ (sqrt((float)(sTwips.iHeight*sTwips.iHeight + sTwips.iWidth*sTwips.iWidth)) / KTwipsPerInch);
|
||||||
return dpi / 170.0f;
|
return dpi / 170.0f;
|
||||||
#else
|
#else
|
||||||
|
// Sane default for Blackberry and Meego
|
||||||
return 1.2f;
|
return 1.2f;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -41,10 +58,16 @@ int main(int argc, char *argv[])
|
||||||
QT_TRAP_THROWING(dynamic_cast<CAknAppUi*>(CEikonEnv::Static()->AppUi())->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape));
|
QT_TRAP_THROWING(dynamic_cast<CAknAppUi*>(CEikonEnv::Static()->AppUi())->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape));
|
||||||
#endif
|
#endif
|
||||||
QSize res = QApplication::desktop()->screenGeometry().size();
|
QSize res = QApplication::desktop()->screenGeometry().size();
|
||||||
|
#ifdef USING_GLES2
|
||||||
if (res.width() < res.height())
|
if (res.width() < res.height())
|
||||||
res.transpose();
|
res.transpose();
|
||||||
pixel_xres = res.width();
|
pixel_xres = res.width();
|
||||||
pixel_yres = res.height();
|
pixel_yres = res.height();
|
||||||
|
#else
|
||||||
|
// Set resolution to half of the monitor on desktop systems
|
||||||
|
pixel_xres = res.width() / 2;
|
||||||
|
pixel_yres = res.height() / 2;
|
||||||
|
#endif
|
||||||
float dpi_scale = CalculateDPIScale();
|
float dpi_scale = CalculateDPIScale();
|
||||||
dp_xres = (int)(pixel_xres * dpi_scale); dp_yres = (int)(pixel_yres * dpi_scale);
|
dp_xres = (int)(pixel_xres * dpi_scale); dp_yres = (int)(pixel_yres * dpi_scale);
|
||||||
net::Init();
|
net::Init();
|
||||||
|
@ -55,9 +78,14 @@ int main(int argc, char *argv[])
|
||||||
#else
|
#else
|
||||||
NativeInit(argc, (const char **)argv, "./", "/tmp", "BADCOFFEE");
|
NativeInit(argc, (const char **)argv, "./", "/tmp", "BADCOFFEE");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MainUI w(dpi_scale);
|
MainUI w(dpi_scale);
|
||||||
w.resize(pixel_xres, pixel_yres);
|
w.resize(pixel_xres, pixel_yres);
|
||||||
|
#ifdef USING_GLES2
|
||||||
w.showFullScreen();
|
w.showFullScreen();
|
||||||
|
#else
|
||||||
|
w.show();
|
||||||
|
#endif
|
||||||
|
|
||||||
MainAudio *audio = new MainAudio();
|
MainAudio *audio = new MainAudio();
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,30 @@
|
||||||
#include "net/resolve.h"
|
#include "net/resolve.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
||||||
|
// Input
|
||||||
|
const int buttonMappings[18] = {
|
||||||
|
Qt::Key_X, //A
|
||||||
|
Qt::Key_S, //B
|
||||||
|
Qt::Key_Z, //X
|
||||||
|
Qt::Key_A, //Y
|
||||||
|
Qt::Key_W, //LBUMPER
|
||||||
|
Qt::Key_Q, //RBUMPER
|
||||||
|
Qt::Key_1, //START
|
||||||
|
Qt::Key_2, //SELECT
|
||||||
|
Qt::Key_Up, //UP
|
||||||
|
Qt::Key_Down, //DOWN
|
||||||
|
Qt::Key_Left, //LEFT
|
||||||
|
Qt::Key_Right, //RIGHT
|
||||||
|
0, //MENU (event)
|
||||||
|
Qt::Key_Backspace, //BACK
|
||||||
|
Qt::Key_I, //JOY UP
|
||||||
|
Qt::Key_K, //JOY DOWN
|
||||||
|
Qt::Key_J, //JOY LEFT
|
||||||
|
Qt::Key_L, //JOY RIGHT
|
||||||
|
};
|
||||||
|
void SimulateGamepad(InputState *input);
|
||||||
|
|
||||||
|
//GUI
|
||||||
class MainUI : public QGLWidget
|
class MainUI : public QGLWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -32,6 +56,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void resizeEvent(QResizeEvent * e)
|
||||||
|
{
|
||||||
|
pixel_xres = e->size().width();
|
||||||
|
pixel_yres = e->size().height();
|
||||||
|
dp_xres = pixel_xres * dpi_scale;
|
||||||
|
dp_yres = pixel_yres * dpi_scale;
|
||||||
|
}
|
||||||
|
|
||||||
bool event(QEvent *e)
|
bool event(QEvent *e)
|
||||||
{
|
{
|
||||||
QList<QTouchEvent::TouchPoint> touchPoints;
|
QList<QTouchEvent::TouchPoint> touchPoints;
|
||||||
|
@ -64,6 +96,18 @@ protected:
|
||||||
input_state.pointer_x[0] = ((QMouseEvent*)e)->pos().x() * dpi_scale;
|
input_state.pointer_x[0] = ((QMouseEvent*)e)->pos().x() * dpi_scale;
|
||||||
input_state.pointer_y[0] = ((QMouseEvent*)e)->pos().y() * dpi_scale;
|
input_state.pointer_y[0] = ((QMouseEvent*)e)->pos().y() * dpi_scale;
|
||||||
break;
|
break;
|
||||||
|
case QEvent::KeyPress:
|
||||||
|
for (int b = 0; b < 14; b++) {
|
||||||
|
if (((QKeyEvent*)e)->key() == buttonMappings[b])
|
||||||
|
input_state.pad_buttons |= (1<<b);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case QEvent::KeyRelease:
|
||||||
|
for (int b = 0; b < 14; b++) {
|
||||||
|
if (((QKeyEvent*)e)->key() == buttonMappings[b])
|
||||||
|
input_state.pad_buttons &= ~(1<<b);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return QWidget::event(e);
|
return QWidget::event(e);
|
||||||
}
|
}
|
||||||
|
@ -81,6 +125,7 @@ protected:
|
||||||
|
|
||||||
void paintGL()
|
void paintGL()
|
||||||
{
|
{
|
||||||
|
SimulateGamepad(&input_state);
|
||||||
UpdateInputState(&input_state);
|
UpdateInputState(&input_state);
|
||||||
NativeUpdate(input_state);
|
NativeUpdate(input_state);
|
||||||
EndInputState(&input_state);
|
EndInputState(&input_state);
|
||||||
|
@ -94,6 +139,7 @@ private:
|
||||||
float dpi_scale;
|
float dpi_scale;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Audio
|
||||||
#define AUDIO_FREQ 44100
|
#define AUDIO_FREQ 44100
|
||||||
#define AUDIO_CHANNELS 2
|
#define AUDIO_CHANNELS 2
|
||||||
#define AUDIO_SAMPLES 1024
|
#define AUDIO_SAMPLES 1024
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue