Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 31 additions & 26 deletions engine/src/adapters/mobileadaptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class DefaultHandler : public LogHandler {
#define PRESS 1
#define REPEAT 2

static GLFMDisplay *gDisplay = nullptr;
static Engine *g_pEngine = nullptr;
static GLFMDisplay *s_display = nullptr;
static Engine *s_engine = nullptr;

static std::unordered_map<int32_t, int32_t> s_keys;
static std::unordered_map<int32_t, std::pair<uint32_t, Vector4>> s_touches;
Expand Down Expand Up @@ -166,10 +166,10 @@ int keyToInput(int key) {
}

void onFrame(GLFMDisplay *display) {
if(g_pEngine) {
if(s_engine) {
Timer::update();

g_pEngine->update();
s_engine->update();
}

glfmSwapBuffers(display);
Expand All @@ -195,9 +195,9 @@ void onCreate(GLFMDisplay *, int width, int height) {
#endif
#endif

g_pEngine = new Engine(file, path);
s_engine = new Engine(file, path);

thunderMain(g_pEngine);
thunderMain(s_engine);
}

void onResize(GLFMDisplay *, int width, int height) {
Expand All @@ -215,10 +215,11 @@ bool onTouch(GLFMDisplay *, int touch, GLFMTouchPhase phase, double x, double y)
}
#else
if(phase < GLFMTouchPhaseCancelled) {
Vector4 pos(x, MobileAdaptor::s_height - y,
x / (float)MobileAdaptor::s_width, (MobileAdaptor::s_height - y) / (float)MobileAdaptor::s_width);

if(touch == 0) {
MobileAdaptor::s_oldMousePosition = MobileAdaptor::s_mousePosition;
MobileAdaptor::s_mousePosition = Vector4(x, MobileAdaptor::s_height - y,
x / (float)MobileAdaptor::s_width, (MobileAdaptor::s_height - y) / (float)MobileAdaptor::s_width);
MobileAdaptor::s_mousePosition = pos;
}

int index = touch;
Expand All @@ -237,7 +238,7 @@ bool onTouch(GLFMDisplay *, int touch, GLFMTouchPhase phase, double x, double y)
default: break;
}

s_touches[index] = std::make_pair(state, MobileAdaptor::s_mousePosition);
s_touches[index] = std::make_pair(state, pos);
} else {
auto it = s_touches.find(touch);
if(it != s_touches.end()) {
Expand Down Expand Up @@ -265,7 +266,6 @@ bool onKey(GLFMDisplay *, GLFMKeyCode keyCode, GLFMKeyAction action, int) {
bool onMouseWeel(GLFMDisplay *, double x, double y, GLFMMouseWheelDeltaType deltaType,
double, double deltaY, double) {

MobileAdaptor::s_oldMousePosition = MobileAdaptor::s_mousePosition;
MobileAdaptor::s_mousePosition = Vector4(x, MobileAdaptor::s_height - y,
x / (float)MobileAdaptor::s_width, (MobileAdaptor::s_height - y) / (float)MobileAdaptor::s_width);

Expand All @@ -279,24 +279,24 @@ void onChar(GLFMDisplay *, const char *utf8, int) {
}

void glfmMain(GLFMDisplay *display) {
gDisplay = display;
s_display = display;

glfmSetDisplayConfig(gDisplay,
glfmSetDisplayConfig(s_display,
GLFMRenderingAPIOpenGLES3,
GLFMColorFormatRGBA8888,
GLFMDepthFormat16,
GLFMStencilFormatNone,
GLFMMultisampleNone);

glfmSetRenderFunc(gDisplay, onFrame);
glfmSetSurfaceCreatedFunc(gDisplay, onCreate);
glfmSetSurfaceResizedFunc(gDisplay, onResize);
glfmSetRenderFunc(s_display, onFrame);
glfmSetSurfaceCreatedFunc(s_display, onCreate);
glfmSetSurfaceResizedFunc(s_display, onResize);

glfmSetTouchFunc(gDisplay, onTouch);
glfmSetKeyFunc(gDisplay, onKey);
glfmSetCharFunc(gDisplay, onChar);
glfmSetTouchFunc(s_display, onTouch);
glfmSetKeyFunc(s_display, onKey);
glfmSetCharFunc(s_display, onChar);

glfmSetMouseWheelFunc(gDisplay, onMouseWeel);
glfmSetMouseWheelFunc(s_display, onMouseWeel);
}

MobileAdaptor::MobileAdaptor() {
Expand Down Expand Up @@ -358,7 +358,7 @@ bool MobileAdaptor::isValid() {

std::string MobileAdaptor::locationLocalDir() const {
#ifdef __ANDROID__
return reinterpret_cast<ANativeActivity *>(glfmGetAndroidActivity(gDisplay))->internalDataPath;
return reinterpret_cast<ANativeActivity *>(glfmGetAndroidActivity(s_display))->internalDataPath;
#else
return configLocation();
#endif
Expand Down Expand Up @@ -402,7 +402,7 @@ std::string MobileAdaptor::inputString() const {

void MobileAdaptor::setKeyboardVisible(bool visible) {
#ifndef __EMSCRIPTEN__
glfmSetKeyboardVisible(gDisplay, visible);
glfmSetKeyboardVisible(s_display, visible);
#endif
}

Expand Down Expand Up @@ -444,23 +444,28 @@ bool MobileAdaptor::mouseReleased(int button) const {

void MobileAdaptor::mouseLockCursor(bool lock) {
s_mouseLocked = lock;
//glfmSetMouseCursor(gDisplay, s_mouseLocked ? GLFMMouseCursorNone : GLFMMouseCursorAuto);
}

uint32_t MobileAdaptor::touchCount() const {
return s_touches.size();
int result = 0;
for(auto it : s_touches) {
if(it.second.first != NONE) {
result++;
}
}
return result;
}

uint32_t MobileAdaptor::touchState(int index) const {
auto it = s_touches.find(index);
auto it = s_touches.find(index | Input::MOUSE_LEFT);
if(it != s_touches.end()) {
return it->second.first;
}
return 0;
}

Vector4 MobileAdaptor::touchPosition(int index) const {
auto it = s_touches.find(index);
auto it = s_touches.find(index | Input::MOUSE_LEFT);
if(it != s_touches.end()) {
return it->second.second;
}
Expand Down
1 change: 1 addition & 0 deletions engine/src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Engine::Engine(File *file, const char *path) {

m_file = file;


World::registerClassFactory(m_instance);
Scene::registerClassFactory(m_instance);
Actor::registerClassFactory(m_instance);
Expand Down
2 changes: 1 addition & 1 deletion modules/uikit/src/components/abstractbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void AbstractButton::update() {
Vector4 color(m_normalColor);

bool hover = (m_background) ? m_background->rectTransform()->isHovered(pos.x, pos.y) : rectTransform()->isHovered(pos.x, pos.y);
if(m_hovered != hover || hover) {
if(m_hovered != hover) {
m_currentFade = 0.0f;
m_hovered = hover;
}
Expand Down
Loading