make work on Windows again
This commit is contained in:
parent
eeb46ac795
commit
4c5d1d0ca5
|
@ -26,7 +26,7 @@ MESSAGE(STATUS "BUILD TYPE: " ${CMAKE_BUILD_TYPE})
|
||||||
# setup compiler options
|
# setup compiler options
|
||||||
IF(CMAKE_COMPILER_IS_GNUCXX)
|
IF(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
SET(CXX_WARNS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-variable -Wno-switch")
|
SET(CXX_WARNS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-variable -Wno-switch")
|
||||||
SET(CMAKE_CXX_FLAGS "-std=c++0x -pipe ${CXX_WARNS}")
|
SET(CMAKE_CXX_FLAGS "-std=gnu++0x -pipe ${CXX_WARNS}")
|
||||||
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -ggdb3 -fno-inline")
|
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -ggdb3 -fno-inline")
|
||||||
SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -rdynamic")
|
SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -rdynamic")
|
||||||
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O1 -g -fno-inline")
|
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O1 -g -fno-inline")
|
||||||
|
@ -170,4 +170,5 @@ ENDIF(USE_PCH)
|
||||||
# installation
|
# installation
|
||||||
SET(DATA_INSTALL_DIR share/otclient)
|
SET(DATA_INSTALL_DIR share/otclient)
|
||||||
INSTALL(TARGETS otclient RUNTIME DESTINATION bin)
|
INSTALL(TARGETS otclient RUNTIME DESTINATION bin)
|
||||||
INSTALL(DIRECTORY modules DESTINATION ${DATA_INSTALL_DIR})
|
INSTALL(DIRECTORY modules DESTINATION ${DATA_INSTALL_DIR}
|
||||||
|
PATTERN ".git" EXCLUDE)
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "graphics.h"
|
#include "graphics.h"
|
||||||
|
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
|
#include <GL/glext.h>
|
||||||
|
|
||||||
Texture::Texture()
|
Texture::Texture()
|
||||||
{
|
{
|
||||||
|
|
|
@ -84,7 +84,6 @@ public:
|
||||||
std::string generateBacktrace(int maxLevel = 100);
|
std::string generateBacktrace(int maxLevel = 100);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PlatformListener* m_listener;
|
|
||||||
int m_lastTicks;
|
int m_lastTicks;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,9 +20,8 @@
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <global.h>
|
#include "platform.h"
|
||||||
#include <core/platform.h>
|
#include "platformlistener.h"
|
||||||
#include <core/engine.h>
|
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <dir.h>
|
#include <dir.h>
|
||||||
|
@ -36,23 +35,26 @@ struct Win32PlatformPrivate {
|
||||||
HINSTANCE instance;
|
HINSTANCE instance;
|
||||||
HDC hdc;
|
HDC hdc;
|
||||||
HGLRC hrc;
|
HGLRC hrc;
|
||||||
|
|
||||||
std::string appName;
|
std::string appName;
|
||||||
int x, y;
|
int x, y;
|
||||||
int width, height;
|
int width, height;
|
||||||
int minWidth, minHeight;
|
int minWidth, minHeight;
|
||||||
bool focused, visible, maximized;
|
bool focused, visible, maximized;
|
||||||
|
std::map<int, Fw::Key> keyMap;
|
||||||
std::map<int, uchar> keyMap;
|
PlatformListener* listener;
|
||||||
|
PlatformEvent platformEvent;
|
||||||
} win32;
|
} win32;
|
||||||
|
|
||||||
void Platform::init(const char *appName)
|
Platform g_platform;
|
||||||
|
|
||||||
|
void Platform::init(PlatformListener* platformListener, const char *appName)
|
||||||
{
|
{
|
||||||
// seend random numbers
|
// seend random numbers
|
||||||
std::srand(std::time(NULL));
|
std::srand(std::time(NULL));
|
||||||
|
|
||||||
win32.appName = appName;
|
win32.appName = appName;
|
||||||
win32.instance = GetModuleHandle(NULL);
|
win32.instance = GetModuleHandle(NULL);
|
||||||
|
win32.listener = platformListener;
|
||||||
|
|
||||||
win32.keyMap[VK_ESCAPE] = Fw::KeyEscape;
|
win32.keyMap[VK_ESCAPE] = Fw::KeyEscape;
|
||||||
win32.keyMap[VK_TAB] = Fw::KeyTab;
|
win32.keyMap[VK_TAB] = Fw::KeyTab;
|
||||||
|
@ -188,30 +190,30 @@ void Platform::init(const char *appName)
|
||||||
win32.keyMap[VK_NUMPAD8] = Fw::KeyNumpad8;
|
win32.keyMap[VK_NUMPAD8] = Fw::KeyNumpad8;
|
||||||
win32.keyMap[VK_NUMPAD9] = Fw::KeyNumpad9;
|
win32.keyMap[VK_NUMPAD9] = Fw::KeyNumpad9;
|
||||||
|
|
||||||
win32.keyMap[VK_OEM_1] = KeySemicolon;
|
win32.keyMap[VK_OEM_1] = Fw::KeySemicolon;
|
||||||
win32.keyMap[VK_OEM_2] = KeySlash;
|
win32.keyMap[VK_OEM_2] = Fw::KeySlash;
|
||||||
win32.keyMap[VK_OEM_3] = KeyGrave;
|
win32.keyMap[VK_OEM_3] = Fw::KeyGrave;
|
||||||
win32.keyMap[VK_OEM_4] = KeyLeftBracket;
|
win32.keyMap[VK_OEM_4] = Fw::KeyLeftBracket;
|
||||||
win32.keyMap[VK_OEM_5] = KeyBackslash;
|
win32.keyMap[VK_OEM_5] = Fw::KeyBackslash;
|
||||||
win32.keyMap[VK_OEM_6] = KeyRightBracket;
|
win32.keyMap[VK_OEM_6] = Fw::KeyRightBracket;
|
||||||
win32.keyMap[VK_OEM_7] = KeyApostrophe;
|
win32.keyMap[VK_OEM_7] = Fw::KeyApostrophe;
|
||||||
win32.keyMap[VK_OEM_MINUS] = KeyMinus;
|
win32.keyMap[VK_OEM_MINUS] = Fw::KeyMinus;
|
||||||
win32.keyMap[VK_OEM_PLUS] = KeyPlus;
|
win32.keyMap[VK_OEM_PLUS] = Fw::KeyPlus;
|
||||||
win32.keyMap[VK_OEM_COMMA] = KeyComma;
|
win32.keyMap[VK_OEM_COMMA] = Fw::KeyComma;
|
||||||
win32.keyMap[VK_OEM_PERIOD] = KeyPeriod;
|
win32.keyMap[VK_OEM_PERIOD] = Fw::KeyPeriod;
|
||||||
|
|
||||||
win32.keyMap[VK_F1] = KeyF1;
|
win32.keyMap[VK_F1] = Fw::KeyF1;
|
||||||
win32.keyMap[VK_F2] = KeyF2;
|
win32.keyMap[VK_F2] = Fw::KeyF2;
|
||||||
win32.keyMap[VK_F3] = KeyF3;
|
win32.keyMap[VK_F3] = Fw::KeyF3;
|
||||||
win32.keyMap[VK_F4] = KeyF4;
|
win32.keyMap[VK_F4] = Fw::KeyF4;
|
||||||
win32.keyMap[VK_F5] = KeyF5;
|
win32.keyMap[VK_F5] = Fw::KeyF5;
|
||||||
win32.keyMap[VK_F6] = KeyF6;
|
win32.keyMap[VK_F6] = Fw::KeyF6;
|
||||||
win32.keyMap[VK_F7] = KeyF7;
|
win32.keyMap[VK_F7] = Fw::KeyF7;
|
||||||
win32.keyMap[VK_F8] = KeyF8;
|
win32.keyMap[VK_F8] = Fw::KeyF8;
|
||||||
win32.keyMap[VK_F9] = KeyF9;
|
win32.keyMap[VK_F9] = Fw::KeyF9;
|
||||||
win32.keyMap[VK_F10] = KeyF10;
|
win32.keyMap[VK_F10] = Fw::KeyF10;
|
||||||
win32.keyMap[VK_F11] = KeyF11;
|
win32.keyMap[VK_F11] = Fw::KeyF11;
|
||||||
win32.keyMap[VK_F12] = KeyF12;
|
win32.keyMap[VK_F12] = Fw::KeyF12;
|
||||||
|
|
||||||
// win class
|
// win class
|
||||||
WNDCLASSA wc;
|
WNDCLASSA wc;
|
||||||
|
@ -230,7 +232,7 @@ void Platform::init(const char *appName)
|
||||||
logFatal("FATAL ERROR: Failed to register the window class.");
|
logFatal("FATAL ERROR: Failed to register the window class.");
|
||||||
|
|
||||||
// force first tick
|
// force first tick
|
||||||
Platform::getTicks();
|
updateTicks();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::terminate()
|
void Platform::terminate()
|
||||||
|
@ -257,13 +259,13 @@ void Platform::poll()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Platform::getTicks()
|
void Platform::updateTicks()
|
||||||
{
|
{
|
||||||
static ulong firstTick = 0;
|
static ulong firstTick = 0;
|
||||||
if(!firstTick)
|
if(!firstTick)
|
||||||
firstTick = GetTickCount();
|
firstTick = GetTickCount();
|
||||||
|
|
||||||
return (uint32_t)(GetTickCount() - firstTick);
|
m_lastTicks = (uint32_t)(GetTickCount() - firstTick);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::sleep(ulong miliseconds)
|
void Platform::sleep(ulong miliseconds)
|
||||||
|
@ -306,7 +308,7 @@ bool Platform::createWindow(int x, int y, int width, int height, int minWidth, i
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint pixelFormat;
|
uint pixelFormat;
|
||||||
static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be
|
static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be
|
||||||
{
|
{
|
||||||
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
|
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
|
||||||
|
@ -397,6 +399,11 @@ void Platform::showWindow()
|
||||||
ShowWindow(win32.window, SW_SHOW);
|
ShowWindow(win32.window, SW_SHOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Platform::hideWindow()
|
||||||
|
{
|
||||||
|
ShowWindow(win32.window, SW_HIDE);
|
||||||
|
}
|
||||||
|
|
||||||
void Platform::setWindowTitle(const char *title)
|
void Platform::setWindowTitle(const char *title)
|
||||||
{
|
{
|
||||||
SetWindowTextA(win32.window, title);
|
SetWindowTextA(win32.window, title);
|
||||||
|
@ -451,9 +458,14 @@ void Platform::showMouseCursor()
|
||||||
ShowCursor(true);
|
ShowCursor(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Point Platform::getMouseCursorPos()
|
||||||
|
{
|
||||||
|
return win32.platformEvent.mousePos;
|
||||||
|
}
|
||||||
|
|
||||||
void Platform::setVerticalSync(bool enable /*= true*/)
|
void Platform::setVerticalSync(bool enable /*= true*/)
|
||||||
{
|
{
|
||||||
typedef GLint (*glSwapIntervalProc)(GLint);
|
typedef int (*glSwapIntervalProc)(int);
|
||||||
glSwapIntervalProc glSwapInterval = NULL;
|
glSwapIntervalProc glSwapInterval = NULL;
|
||||||
|
|
||||||
if(isExtensionSupported("WGL_EXT_swap_control"))
|
if(isExtensionSupported("WGL_EXT_swap_control"))
|
||||||
|
@ -525,7 +537,7 @@ std::string Platform::getAppUserDir()
|
||||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
static int lastX, lastY;
|
static int lastX, lastY;
|
||||||
static InputEvent inputEvent;
|
PlatformEvent& platformEvent = win32.platformEvent;
|
||||||
|
|
||||||
switch(uMsg)
|
switch(uMsg)
|
||||||
{
|
{
|
||||||
|
@ -537,16 +549,19 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
case WM_CHAR:
|
case WM_CHAR:
|
||||||
{
|
{
|
||||||
if(wParam >= 32 && wParam <= 255) {
|
if(wParam >= 32 && wParam <= 255) {
|
||||||
inputEvent.type = EV_TEXT_ENTER;
|
platformEvent.type = EventKeyDown;
|
||||||
inputEvent.keychar = wParam;
|
platformEvent.ctrl = HIWORD(GetKeyState(VK_CONTROL)) == 0 ? false : true;
|
||||||
inputEvent.keycode = KeyUNKNOWN;
|
platformEvent.alt = HIWORD(GetKeyState(VK_MENU)) == 0 ? false : true;
|
||||||
g_engine.onInputEvent(inputEvent);
|
platformEvent.shift = HIWORD(GetKeyState(VK_SHIFT)) == 0 ? false : true;
|
||||||
|
platformEvent.keychar = wParam;
|
||||||
|
platformEvent.keycode = Fw::KeyUnknown;
|
||||||
|
win32.listener->onPlatformEvent(platformEvent);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
{
|
{
|
||||||
g_engine.onClose();
|
win32.listener->onClose();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_GETMINMAXINFO:
|
case WM_GETMINMAXINFO:
|
||||||
|
@ -560,64 +575,65 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
case WM_KEYUP:
|
case WM_KEYUP:
|
||||||
{
|
{
|
||||||
if(win32.keyMap.find(wParam) != win32.keyMap.end()) {
|
if(win32.keyMap.find(wParam) != win32.keyMap.end()) {
|
||||||
inputEvent.type = uMsg == WM_KEYDOWN ? EV_KEY_DOWN : EV_KEY_UP;
|
platformEvent.type = uMsg == WM_KEYDOWN ? EventKeyDown : EventKeyUp;
|
||||||
inputEvent.ctrl = HIWORD(GetKeyState(VK_CONTROL)) == 0 ? false : true;
|
platformEvent.ctrl = HIWORD(GetKeyState(VK_CONTROL)) == 0 ? false : true;
|
||||||
inputEvent.alt = HIWORD(GetKeyState(VK_MENU)) == 0 ? false : true;
|
platformEvent.alt = HIWORD(GetKeyState(VK_MENU)) == 0 ? false : true;
|
||||||
inputEvent.shift = HIWORD(GetKeyState(VK_SHIFT)) == 0 ? false : true;
|
platformEvent.shift = HIWORD(GetKeyState(VK_SHIFT)) == 0 ? false : true;
|
||||||
inputEvent.keycode = win32.keyMap[wParam];
|
platformEvent.keycode = win32.keyMap[wParam];
|
||||||
|
platformEvent.keychar = 0;
|
||||||
}
|
}
|
||||||
g_engine.onInputEvent(inputEvent);
|
win32.listener->onPlatformEvent(platformEvent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_LBUTTONDOWN:
|
case WM_LBUTTONDOWN:
|
||||||
{
|
{
|
||||||
inputEvent.type = EV_MOUSE_LDOWN;
|
platformEvent.type = EventMouseLeftButtonDown;
|
||||||
g_engine.onInputEvent(inputEvent);
|
win32.listener->onPlatformEvent(platformEvent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_LBUTTONUP:
|
case WM_LBUTTONUP:
|
||||||
{
|
{
|
||||||
inputEvent.type = EV_MOUSE_LUP;
|
platformEvent.type = EventMouseLeftButtonUp;
|
||||||
g_engine.onInputEvent(inputEvent);
|
win32.listener->onPlatformEvent(platformEvent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_MBUTTONDOWN:
|
case WM_MBUTTONDOWN:
|
||||||
{
|
{
|
||||||
inputEvent.type = EV_MOUSE_MDOWN;
|
platformEvent.type = EventMouseMiddleButtonDown;
|
||||||
g_engine.onInputEvent(inputEvent);
|
win32.listener->onPlatformEvent(platformEvent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_MBUTTONUP:
|
case WM_MBUTTONUP:
|
||||||
{
|
{
|
||||||
inputEvent.type = EV_MOUSE_MUP;
|
platformEvent.type = EventMouseMiddleButtonUp;
|
||||||
g_engine.onInputEvent(inputEvent);
|
win32.listener->onPlatformEvent(platformEvent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_RBUTTONDOWN:
|
case WM_RBUTTONDOWN:
|
||||||
{
|
{
|
||||||
inputEvent.type = EV_MOUSE_RDOWN;
|
platformEvent.type = EventMouseRightButtonDown;
|
||||||
g_engine.onInputEvent(inputEvent);
|
win32.listener->onPlatformEvent(platformEvent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_RBUTTONUP:
|
case WM_RBUTTONUP:
|
||||||
{
|
{
|
||||||
inputEvent.type = EV_MOUSE_RUP;
|
platformEvent.type = EventMouseRightButtonUp;
|
||||||
g_engine.onInputEvent(inputEvent);
|
win32.listener->onPlatformEvent(platformEvent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_MOUSEMOVE:
|
case WM_MOUSEMOVE:
|
||||||
{
|
{
|
||||||
inputEvent.type = EV_MOUSE_MOVE;
|
platformEvent.type = EventMouseMove;
|
||||||
Point newMousePos(LOWORD(lParam), HIWORD(lParam));
|
Point newMousePos(LOWORD(lParam), HIWORD(lParam));
|
||||||
inputEvent.mouseMoved = newMousePos - inputEvent.mousePos;
|
platformEvent.mouseMoved = newMousePos - platformEvent.mousePos;
|
||||||
inputEvent.mousePos = newMousePos;
|
platformEvent.mousePos = newMousePos;
|
||||||
g_engine.onInputEvent(inputEvent);
|
win32.listener->onPlatformEvent(platformEvent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_MOUSEWHEEL:
|
case WM_MOUSEWHEEL:
|
||||||
{
|
{
|
||||||
inputEvent.type = HIWORD(wParam) > 0 ? EV_MOUSE_WHEEL_UP : EV_MOUSE_WHEEL_DOWN;
|
platformEvent.type = HIWORD(wParam) > 0 ? EventMouseWheelUp : EventMouseWheelDown;
|
||||||
g_engine.onInputEvent(inputEvent);
|
win32.listener->onPlatformEvent(platformEvent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_MOVE:
|
case WM_MOVE:
|
||||||
|
@ -649,7 +665,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
win32.height = HIWORD(lParam);
|
win32.height = HIWORD(lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_engine.onResize(Size(LOWORD(lParam), HIWORD(lParam)));
|
win32.listener->onResize(Size(LOWORD(lParam), HIWORD(lParam)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -64,7 +64,8 @@ struct X11PlatformPrivate {
|
||||||
int lastTicks;
|
int lastTicks;
|
||||||
std::string clipboardText;
|
std::string clipboardText;
|
||||||
std::map<int, Fw::Key> keyMap;
|
std::map<int, Fw::Key> keyMap;
|
||||||
PlatformEvent inputEvent;
|
PlatformListener* listener;
|
||||||
|
PlatformEvent platformEvent;
|
||||||
} x11;
|
} x11;
|
||||||
|
|
||||||
Platform g_platform;
|
Platform g_platform;
|
||||||
|
@ -88,7 +89,7 @@ void Platform::init(PlatformListener* platformListener, const char *appName)
|
||||||
x11.width = 0;
|
x11.width = 0;
|
||||||
x11.height = 0;
|
x11.height = 0;
|
||||||
x11.maximizeOnFirstShow = false;
|
x11.maximizeOnFirstShow = false;
|
||||||
m_listener = platformListener;
|
x11.listener = platformListener;
|
||||||
|
|
||||||
x11.keyMap[XK_Escape] = Fw::KeyEscape;
|
x11.keyMap[XK_Escape] = Fw::KeyEscape;
|
||||||
x11.keyMap[XK_Tab] = Fw::KeyTab;
|
x11.keyMap[XK_Tab] = Fw::KeyTab;
|
||||||
|
@ -294,7 +295,7 @@ void Platform::terminate()
|
||||||
void Platform::poll()
|
void Platform::poll()
|
||||||
{
|
{
|
||||||
XEvent event, peekevent;
|
XEvent event, peekevent;
|
||||||
PlatformEvent& inputEvent = x11.inputEvent;
|
PlatformEvent& platformEvent = x11.platformEvent;
|
||||||
while(XPending(x11.display) > 0) {
|
while(XPending(x11.display) > 0) {
|
||||||
XNextEvent(x11.display, &event);
|
XNextEvent(x11.display, &event);
|
||||||
|
|
||||||
|
@ -317,7 +318,7 @@ void Platform::poll()
|
||||||
static int oldWidth = -1;
|
static int oldWidth = -1;
|
||||||
static int oldHeight = -1;
|
static int oldHeight = -1;
|
||||||
if(oldWidth != event.xconfigure.width || oldHeight != event.xconfigure.height) {
|
if(oldWidth != event.xconfigure.width || oldHeight != event.xconfigure.height) {
|
||||||
m_listener->onResize(Size(event.xconfigure.width, event.xconfigure.height));
|
x11.listener->onResize(Size(event.xconfigure.width, event.xconfigure.height));
|
||||||
oldWidth = event.xconfigure.width;
|
oldWidth = event.xconfigure.width;
|
||||||
oldHeight = event.xconfigure.height;
|
oldHeight = event.xconfigure.height;
|
||||||
}
|
}
|
||||||
|
@ -343,13 +344,13 @@ void Platform::poll()
|
||||||
char buf[32];
|
char buf[32];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
inputEvent.ctrl = (event.xkey.state & ControlMask);
|
platformEvent.ctrl = (event.xkey.state & ControlMask);
|
||||||
inputEvent.shift = (event.xkey.state & ShiftMask);
|
platformEvent.shift = (event.xkey.state & ShiftMask);
|
||||||
inputEvent.alt = (event.xkey.state & Mod1Mask);
|
platformEvent.alt = (event.xkey.state & Mod1Mask);
|
||||||
inputEvent.keychar = 0;
|
platformEvent.keychar = 0;
|
||||||
|
|
||||||
// fire enter text event
|
// fire enter text event
|
||||||
if(event.type == KeyPress && !inputEvent.ctrl && !inputEvent.alt) {
|
if(event.type == KeyPress && !platformEvent.ctrl && !platformEvent.alt) {
|
||||||
if(x11.xic) { // with xim we can get latin1 input correctly
|
if(x11.xic) { // with xim we can get latin1 input correctly
|
||||||
Status status;
|
Status status;
|
||||||
len = XmbLookupString(x11.xic, &event.xkey, buf, sizeof(buf), &keysym, &status);
|
len = XmbLookupString(x11.xic, &event.xkey, buf, sizeof(buf), &keysym, &status);
|
||||||
|
@ -367,57 +368,57 @@ void Platform::poll()
|
||||||
(uchar)(buf[0]) >= 32
|
(uchar)(buf[0]) >= 32
|
||||||
) {
|
) {
|
||||||
//logDebug("char: ", buf[0], " code: ", (uint)buf[0]);
|
//logDebug("char: ", buf[0], " code: ", (uint)buf[0]);
|
||||||
inputEvent.keychar = buf[0];
|
platformEvent.keychar = buf[0];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//event.xkey.state &= ~(ShiftMask | LockMask);
|
//event.xkey.state &= ~(ShiftMask | LockMask);
|
||||||
len = XLookupString(&event.xkey, buf, sizeof(buf), &keysym, 0);
|
len = XLookupString(&event.xkey, buf, sizeof(buf), &keysym, 0);
|
||||||
|
|
||||||
if(len > 0 && (uchar)inputEvent.keychar >= 32)
|
if(len > 0 && (uchar)platformEvent.keychar >= 32)
|
||||||
inputEvent.keychar = (len > 0) ? buf[0] : 0;
|
platformEvent.keychar = (len > 0) ? buf[0] : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(x11.keyMap.find(keysym) != x11.keyMap.end())
|
if(x11.keyMap.find(keysym) != x11.keyMap.end())
|
||||||
inputEvent.keycode = x11.keyMap[keysym];
|
platformEvent.keycode = x11.keyMap[keysym];
|
||||||
else
|
else
|
||||||
inputEvent.keycode = Fw::KeyUnknown;
|
platformEvent.keycode = Fw::KeyUnknown;
|
||||||
|
|
||||||
inputEvent.keycode = x11.keyMap[keysym];
|
platformEvent.keycode = x11.keyMap[keysym];
|
||||||
inputEvent.type = (event.type == KeyPress) ? EventKeyDown : EventKeyUp;
|
platformEvent.type = (event.type == KeyPress) ? EventKeyDown : EventKeyUp;
|
||||||
|
|
||||||
if(inputEvent.keycode != Fw::KeyUnknown || inputEvent.keychar != 0)
|
if(platformEvent.keycode != Fw::KeyUnknown || platformEvent.keychar != 0)
|
||||||
m_listener->onPlatformEvent(inputEvent);
|
x11.listener->onPlatformEvent(platformEvent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ButtonPress:
|
case ButtonPress:
|
||||||
case ButtonRelease:
|
case ButtonRelease:
|
||||||
switch(event.xbutton.button) {
|
switch(event.xbutton.button) {
|
||||||
case Button1:
|
case Button1:
|
||||||
inputEvent.type = (event.type == ButtonPress) ? EventMouseLeftButtonDown : EventMouseLeftButtonUp;
|
platformEvent.type = (event.type == ButtonPress) ? EventMouseLeftButtonDown : EventMouseLeftButtonUp;
|
||||||
break;
|
break;
|
||||||
case Button3:
|
case Button3:
|
||||||
inputEvent.type = (event.type == ButtonPress) ? EventMouseRightButtonDown : EventMouseRightButtonUp;
|
platformEvent.type = (event.type == ButtonPress) ? EventMouseRightButtonDown : EventMouseRightButtonUp;
|
||||||
break;
|
break;
|
||||||
case Button2:
|
case Button2:
|
||||||
inputEvent.type = (event.type == ButtonPress) ? EventMouseMiddleButtonDown : EventMouseMiddleButtonUp;
|
platformEvent.type = (event.type == ButtonPress) ? EventMouseMiddleButtonDown : EventMouseMiddleButtonUp;
|
||||||
break;
|
break;
|
||||||
case Button4:
|
case Button4:
|
||||||
inputEvent.type = EventMouseWheelUp;
|
platformEvent.type = EventMouseWheelUp;
|
||||||
break;
|
break;
|
||||||
case Button5:
|
case Button5:
|
||||||
inputEvent.type = EventMouseWheelDown;
|
platformEvent.type = EventMouseWheelDown;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
m_listener->onPlatformEvent(inputEvent);
|
x11.listener->onPlatformEvent(platformEvent);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MotionNotify:
|
case MotionNotify:
|
||||||
{
|
{
|
||||||
inputEvent.type = EventMouseMove;
|
platformEvent.type = EventMouseMove;
|
||||||
Point newMousePos(event.xbutton.x, event.xbutton.y);
|
Point newMousePos(event.xbutton.x, event.xbutton.y);
|
||||||
inputEvent.mouseMoved = newMousePos - inputEvent.mousePos;
|
platformEvent.mouseMoved = newMousePos - platformEvent.mousePos;
|
||||||
inputEvent.mousePos = newMousePos;
|
platformEvent.mousePos = newMousePos;
|
||||||
m_listener->onPlatformEvent(inputEvent);
|
x11.listener->onPlatformEvent(platformEvent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,7 +478,7 @@ void Platform::poll()
|
||||||
case ClientMessage:
|
case ClientMessage:
|
||||||
{
|
{
|
||||||
if((Atom)event.xclient.data.l[0] == x11.atomDeleteWindow)
|
if((Atom)event.xclient.data.l[0] == x11.atomDeleteWindow)
|
||||||
m_listener->onClose();
|
x11.listener->onClose();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -595,7 +596,7 @@ bool Platform::createWindow(int x, int y, int width, int height, int minWidth, i
|
||||||
x11.maximizeOnFirstShow = maximized;
|
x11.maximizeOnFirstShow = maximized;
|
||||||
|
|
||||||
// call first onResize
|
// call first onResize
|
||||||
m_listener->onResize(Size(width, height));
|
x11.listener->onResize(Size(width, height));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -768,7 +769,7 @@ void Platform::showMouseCursor()
|
||||||
|
|
||||||
Point Platform::getMouseCursorPos()
|
Point Platform::getMouseCursorPos()
|
||||||
{
|
{
|
||||||
return x11.inputEvent.mousePos;
|
return x11.platformEvent.mousePos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::setVerticalSync(bool enable)
|
void Platform::setVerticalSync(bool enable)
|
||||||
|
|
Loading…
Reference in New Issue