mirror of
https://github.com/edubart/otclient.git
synced 2025-11-03 12:16:23 +01:00
Improved input handler
This commit is contained in:
@@ -53,41 +53,6 @@ void Client::initAppFrameworkAndOTClient(std::vector<std::string>& args)
|
||||
findLuaInitScript();
|
||||
|
||||
g_app.runAppMainLoop();
|
||||
//TODO: restore options
|
||||
/*
|
||||
if(g_graphics.parseOption(arg))
|
||||
continue;
|
||||
|
||||
if(arg == "-version" || arg == "--version" || arg == "-v") {
|
||||
stdext::print(
|
||||
m_appName, " ", m_appVersion, "\n"
|
||||
"Buitt on: ", BUILD_DATE, "\n",
|
||||
"Commit: ", BUILD_COMMIT, "\n",
|
||||
"Compiled by: ", BUILD_COMPILER, "\n",
|
||||
"Build type: ", BUILD_TYPE, "\n");
|
||||
return;
|
||||
} else if(arg == "-help" || arg == "--help" || arg == "-h" || arg == "-?" || arg == "/?") {
|
||||
stdext::print(
|
||||
"Usage: ", args[0], " [options]\n"
|
||||
"Options:\n"
|
||||
" -help Display this information and exit\n"
|
||||
" -version Display version and exit\n"
|
||||
" \n"
|
||||
" -no-fbos Disable usage of opengl framebuffer objects\n"
|
||||
" -no-mipmaps Disable texture mipmaping\n"
|
||||
" -no-smooth Disable texture smoothing (bilinear filter)\n"
|
||||
" -no-non-power-of-two-textures Use only power of two textures\n"
|
||||
" -no-clamp-to-edge Don't use GL_CLAMP_TO_EDGE\n"
|
||||
" -no-backbuffer-cache Don't allow backbuffer caching\n"
|
||||
" -hardware-buffers Cache vertex arrays in hardware\n"
|
||||
" -opengl1 Use OpenGL 1.x painter\n"
|
||||
" -opengl2 Use OpenGL 2.0 painter\n");
|
||||
return;
|
||||
} else {
|
||||
stdext::println("Unrecognized option '", arg, "', please see -help for available options list");
|
||||
return;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void Client::setupAppNameAndVersion() {
|
||||
|
||||
@@ -44,4 +44,8 @@
|
||||
// logger
|
||||
#include "core/logger.h"
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <SDL.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -133,11 +133,6 @@ SDLWindow::SDLWindow() {
|
||||
m_keyMap[SDLK_CARET] = Fw::KeyCaret;
|
||||
m_keyMap[SDLK_UNDERSCORE] = Fw::KeyUnderscore;
|
||||
m_keyMap[SDLK_BACKQUOTE] = Fw::KeyGrave;
|
||||
//m_keyMap['{'] = Fw::KeyLeftCurly;
|
||||
//m_keyMap['|'] = Fw::KeyBar;
|
||||
//m_keyMap['}'] = Fw::KeyRightCurly;
|
||||
//m_keyMap['~'] = Fw::KeyTilde;
|
||||
|
||||
|
||||
// keypad
|
||||
/*
|
||||
@@ -228,9 +223,6 @@ void SDLWindow::poll() {
|
||||
while(SDL_PollEvent(&m_event)) {
|
||||
processKeydownOrKeyrelease();
|
||||
|
||||
if(hasRepeatedKey())
|
||||
continue;
|
||||
|
||||
switch(m_event.type) {
|
||||
case SDL_TEXTINPUT:
|
||||
processTextInput();
|
||||
@@ -240,30 +232,19 @@ void SDLWindow::poll() {
|
||||
processFingerdownAndFingerup();
|
||||
break;
|
||||
case SDL_FINGERMOTION:
|
||||
m_inputEvent.reset();
|
||||
m_inputEvent.type = Fw::MouseMoveInputEvent;
|
||||
Point newMousePos(m_event.tfinger.x * m_mode.w, m_event.tfinger.y * m_mode.h);
|
||||
m_inputEvent.mouseMoved = newMousePos - m_inputEvent.mousePos;
|
||||
m_inputEvent.mousePos = newMousePos;
|
||||
if(m_onInputEvent)
|
||||
m_onInputEvent(m_inputEvent);
|
||||
processFingermotion();
|
||||
break;
|
||||
}
|
||||
|
||||
if(m_inputEvent.type != Fw::NoInputEvent && m_onInputEvent)
|
||||
m_onInputEvent(m_inputEvent);
|
||||
//if(m_inputEvent.type != Fw::NoInputEvent && m_onInputEvent)
|
||||
// m_onInputEvent(m_inputEvent);
|
||||
}
|
||||
|
||||
fireKeysPress();
|
||||
}
|
||||
|
||||
bool SDLWindow::hasRepeatedKey() {
|
||||
g_logger.info(stdext::format("hasRepeatedKey %i", m_event.key.repeat));
|
||||
return m_event.key.repeat != 0;
|
||||
}
|
||||
|
||||
void SDLWindow::processKeydownOrKeyrelease() {
|
||||
if(m_event.key.state == SDL_PRESSED || (m_event.key.state == SDL_RELEASED && !hasRepeatedKey())) {
|
||||
if(m_event.key.state == SDL_PRESSED || m_event.key.state == SDL_RELEASED) {
|
||||
Fw::Key keyCode = Fw::KeyUnknown;
|
||||
SDL_Keycode keysym = m_event.key.keysym.sym;
|
||||
|
||||
@@ -281,7 +262,7 @@ void SDLWindow::processTextInput() {
|
||||
std::string text = m_event.text.text;
|
||||
SDL_Keycode keysym = m_event.key.keysym.sym;
|
||||
|
||||
if(text.length() == 0 || keysym == SDLK_BACKSPACE || keysym == SDLK_RETURN)
|
||||
if(text.length() == 0 || keysym == SDLK_BACKSPACE || keysym == SDLK_RETURN || keysym == SDLK_AC_BACK || keysym == SDLK_DELETE)
|
||||
return;
|
||||
|
||||
if(m_onInputEvent) {
|
||||
@@ -293,23 +274,36 @@ void SDLWindow::processTextInput() {
|
||||
|
||||
void SDLWindow::processFingerdownAndFingerup() {
|
||||
bool isFinderdown = m_event.type == SDL_FINGERDOWN;
|
||||
|
||||
m_inputEvent.reset();
|
||||
m_inputEvent.type = isFinderdown ? Fw::MousePressInputEvent : Fw::MouseReleaseInputEvent;
|
||||
m_inputEvent.mouseButton = Fw::MouseLeftButton;
|
||||
m_mouseButtonStates[Fw::MouseLeftButton] = isFinderdown;
|
||||
|
||||
Point newMousePos(m_event.tfinger.x * m_mode.w, m_event.tfinger.y * m_mode.h);
|
||||
m_inputEvent.mouseMoved = newMousePos - m_inputEvent.mousePos;
|
||||
m_inputEvent.mousePos = newMousePos;
|
||||
|
||||
if(m_onInputEvent)
|
||||
m_onInputEvent(m_inputEvent);
|
||||
}
|
||||
|
||||
void SDLWindow::processFingermotion() {
|
||||
m_inputEvent.reset();
|
||||
m_inputEvent.type = Fw::MouseMoveInputEvent;
|
||||
Point newMousePos(m_event.tfinger.x * m_mode.w, m_event.tfinger.y * m_mode.h);
|
||||
m_inputEvent.mouseMoved = newMousePos - m_inputEvent.mousePos;
|
||||
m_inputEvent.mousePos = newMousePos;
|
||||
if (m_onInputEvent)
|
||||
m_onInputEvent(m_inputEvent);
|
||||
}
|
||||
|
||||
void SDLWindow::swapBuffers() {
|
||||
SDL_GL_SwapWindow(m_window);
|
||||
}
|
||||
|
||||
void SDLWindow::setVerticalSync(bool enable) {
|
||||
// TODO
|
||||
SDL_GL_SetSwapInterval(enable);
|
||||
}
|
||||
|
||||
std::string SDLWindow::getClipboardText() {
|
||||
@@ -326,7 +320,7 @@ Size SDLWindow::getDisplaySize() {
|
||||
}
|
||||
|
||||
std::string SDLWindow::getPlatformType() {
|
||||
return "ANDROID_SDL2";
|
||||
return "MOBILE_SDL2";
|
||||
}
|
||||
|
||||
void SDLWindow::show() {
|
||||
|
||||
@@ -61,10 +61,10 @@ public:
|
||||
|
||||
void initializeSDL();
|
||||
void setSDLAttributes();
|
||||
bool hasRepeatedKey();
|
||||
void processKeydownOrKeyrelease();
|
||||
void processTextInput();
|
||||
void processFingerdownAndFingerup();
|
||||
void processFingermotion();
|
||||
|
||||
protected:
|
||||
int internalLoadMouseCursor(const ImagePtr& image, const Point& hotSpot);
|
||||
|
||||
@@ -659,8 +659,13 @@ void UITextEdit::onFocusChange(bool focused, Fw::FocusReason reason)
|
||||
else
|
||||
blinkCursor();
|
||||
update(true);
|
||||
|
||||
#ifdef ANDROID
|
||||
SDL_StartTextInput();
|
||||
#endif
|
||||
} else if(m_selectable)
|
||||
clearSelection();
|
||||
|
||||
UIWidget::onFocusChange(focused, reason);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,11 +20,6 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// The only way that the android sdl library can link a main function it's including SDL.h
|
||||
#ifdef ANDROID
|
||||
#include <SDL.h>
|
||||
#endif
|
||||
|
||||
#include <client/client.h>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
@@ -34,3 +29,4 @@ int main(int argc, char* argv[])
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user