From c2549af81db4c74841f676d03917e45edac38020 Mon Sep 17 00:00:00 2001 From: "jean.chalard" Date: Sun, 28 Feb 2010 12:31:51 +0000 Subject: [PATCH] J : * Make the FULLSCREEN function bindable on platforms that support it. * Linux has F as default binding. * Windows support is not implemented, but is there ; applications will just not suggest it under windows for the moment. --- JGE/include/JGE.h | 1 + JGE/include/JTypes.h | 1 + JGE/src/JGE.cpp | 21 ++++++++++++++++++++- JGE/src/Xmain.cpp | 8 +++----- JGE/src/winmain.cpp | 8 +++++--- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/JGE/include/JGE.h b/JGE/include/JGE.h index 08e553455..0ceb8ca30 100644 --- a/JGE/include/JGE.h +++ b/JGE/include/JGE.h @@ -46,6 +46,7 @@ void JGECreateDefaultBindings(); int JGEGetTime(); u8 JGEGetAnalogX(); u8 JGEGetAnalogY(); +bool JGEToggleFullscreen(); #if !defined(WIN32) && !defined(LINUX) diff --git a/JGE/include/JTypes.h b/JGE/include/JTypes.h index 39a20944c..82b9045e5 100644 --- a/JGE/include/JTypes.h +++ b/JGE/include/JTypes.h @@ -227,6 +227,7 @@ typedef enum Buttons JGE_BTN_SEC, // Cross or Circle (secondary) JGE_BTN_PREV, // Left trigger JGE_BTN_NEXT, // Right trigger + JGE_BTN_FULLSCREEN, // Switch to fullscreen (obviously, PC only) JGE_BTN_MAX = JGE_BTN_NEXT + 1 } JButton; diff --git a/JGE/src/JGE.cpp b/JGE/src/JGE.cpp index 9970a2515..a96eeed5b 100644 --- a/JGE/src/JGE.cpp +++ b/JGE/src/JGE.cpp @@ -78,11 +78,18 @@ void JGE::PressKey(const LocalKeySym sym) const pair rng = keyBinds.equal_range(sym); if (rng.first == rng.second) keyBuffer.push(triplet(sym, JGE_BTN_NONE, false)); - else for (keycodes_it it = rng.first; it != rng.second; ++it) + else for (keycodes_it it = rng.first; it != rng.second; ++it) { +#if defined (WIN32) || defined (LINUX) + if (JGE_BTN_FULLSCREEN == it->second) JGEToggleFullscreen(); +#endif keyBuffer.push(triplet(*it, held(it->second))); + } } void JGE::PressKey(const JButton sym) { +#if defined (WIN32) || defined (LINUX) + if (sym == JGE_BTN_FULLSCREEN) JGEToggleFullscreen(); +#endif keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, held(sym))); } void JGE::HoldKey(const LocalKeySym sym) @@ -92,6 +99,9 @@ void JGE::HoldKey(const LocalKeySym sym) keyBuffer.push(triplet(sym, JGE_BTN_NONE, false)); else for (keycodes_it it = rng.first; it != rng.second; ++it) { +#if defined (WIN32) || defined (LINUX) + if (JGE_BTN_FULLSCREEN == it->second) JGEToggleFullscreen(); +#endif if (!held(it->second)) { keyBuffer.push(triplet(*it, false)); @@ -107,6 +117,9 @@ void JGE::HoldKey_NoRepeat(const LocalKeySym sym) keyBuffer.push(triplet(sym, JGE_BTN_NONE, false)); else for (keycodes_it it = rng.first; it != rng.second; ++it) { +#if defined (WIN32) || defined (LINUX) + if (JGE_BTN_FULLSCREEN == it->second) JGEToggleFullscreen(); +#endif keyBuffer.push(triplet(*it, true)); if (!held(it->second)) holds[it->second] = std::numeric_limits::quiet_NaN(); @@ -114,6 +127,9 @@ void JGE::HoldKey_NoRepeat(const LocalKeySym sym) } void JGE::HoldKey(const JButton sym) { +#if defined (WIN32) || defined (LINUX) + if (JGE_BTN_FULLSCREEN == sym) JGEToggleFullscreen(); +#endif if (!held(sym)) { keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, false)); @@ -123,6 +139,9 @@ void JGE::HoldKey(const JButton sym) } void JGE::HoldKey_NoRepeat(const JButton sym) { +#if defined (WIN32) || defined (LINUX) + if (JGE_BTN_FULLSCREEN == sym) JGEToggleFullscreen(); +#endif keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, true)); if (!held(sym)) holds[sym] = std::numeric_limits::quiet_NaN(); diff --git a/JGE/src/Xmain.cpp b/JGE/src/Xmain.cpp index 894cd821f..118882e7b 100644 --- a/JGE/src/Xmain.cpp +++ b/JGE/src/Xmain.cpp @@ -77,9 +77,7 @@ static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] { XK_Caps_Lock, JGE_BTN_SEC }, { XK_Shift_L, JGE_BTN_PREV }, { XK_Shift_R, JGE_BTN_NEXT }, - { XK_F1, JGE_BTN_QUIT }, - { XK_F2, JGE_BTN_POWER }, - { XK_F3, JGE_BTN_SOUND } + { XK_F, JGE_BTN_FULLSCREEN }, }; GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize The GL Window @@ -300,7 +298,7 @@ void reshapeFunc(int width, int height) ReSizeGLScene(width, height); } -void fullscreen() +bool JGEToggleFullscreen() { Atom wmState = XInternAtom(gXDisplay, "_NET_WM_STATE", False); Atom fullScreen = XInternAtom(gXDisplay, "_NET_WM_STATE_FULLSCREEN", False); @@ -337,6 +335,7 @@ void fullscreen() XGetWindowAttributes(gXDisplay, DefaultRootWindow(gXDisplay), &xwa); XMoveResizeWindow(gXDisplay, gXWindow, 0, 0, xwa.width, xwa.height); } + return true; } int main(int argc, char* argv[]) @@ -392,7 +391,6 @@ int main(int argc, char* argv[]) case KeyPress: { const KeySym sym = XKeycodeToKeysym(gXDisplay, event.xkey.keycode, 1); - if (sym == XK_F) fullscreen(); g_engine->HoldKey_NoRepeat(sym); } break; diff --git a/JGE/src/winmain.cpp b/JGE/src/winmain.cpp index cd5e17404..7606f897a 100644 --- a/JGE/src/winmain.cpp +++ b/JGE/src/winmain.cpp @@ -179,9 +179,6 @@ static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] { VK_SPACE, JGE_BTN_OK }, { 'K', JGE_BTN_SEC }, { 'J', JGE_BTN_PRI }, - { VK_F1, JGE_BTN_QUIT }, - { VK_F2, JGE_BTN_POWER }, - { VK_F3, JGE_BTN_SOUND } }; void JGECreateDefaultBindings() @@ -634,6 +631,11 @@ LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window return DefWindowProc(hWnd,uMsg,wParam,lParam); } +bool JGEToggleFullscreen() +{ + return false; // Not implemented under windows +} + int WINAPI WinMain( HINSTANCE hInstance, // Instance HINSTANCE hPrevInstance, // Previous Instance LPSTR lpCmdLine, // Command Line Parameters