diff --git a/src/platform/nacl/nacl_instance.cpp b/src/platform/nacl/nacl_instance.cpp index 2a68c81d..b26a69af 100644 --- a/src/platform/nacl/nacl_instance.cpp +++ b/src/platform/nacl/nacl_instance.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include "core.h" #include "debug/quad.h" @@ -31,7 +32,7 @@ NaClInstance::NaClInstance(PP_Instance instance) : pp::Instance(instance), m_size(0, 0) { - ; + RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); } NaClInstance::~NaClInstance() @@ -101,6 +102,25 @@ void NaClInstance::DidChangeView(const pp::Rect& position, const pp::Rect& clip) DrawSelf(); } +bool NaClInstance::HandleInputEvent(const pp::InputEvent& event) +{ + switch (event.GetType()) + { + case PP_INPUTEVENT_TYPE_MOUSEDOWN: + Input::SetMouseButton(pp::MouseInputEvent(event).GetButton()); + break; + case PP_INPUTEVENT_TYPE_MOUSEUP: + Input::UnsetMouseButton(pp::MouseInputEvent(event).GetButton()); + break; + case PP_INPUTEVENT_TYPE_MOUSEMOVE: + Input::SetMousePos(ivec2(pp::MouseInputEvent(event).GetPosition().x(), opengl_context_->GetSize().height() - 1 - pp::MouseInputEvent(event).GetPosition().y())); + break; + default: + break; + } + return true; +} + void NaClInstance::DrawSelf() { if (opengl_context_ == NULL) diff --git a/src/platform/nacl/nacl_instance.h b/src/platform/nacl/nacl_instance.h index 3facd3ae..ab08b891 100644 --- a/src/platform/nacl/nacl_instance.h +++ b/src/platform/nacl/nacl_instance.h @@ -36,14 +36,13 @@ class NaClInstance : public pp::Instance { // Bind and publish the module's methods to JavaScript. //void InitializeMethods(ScriptingBridge* bridge); + // Called to draw the contents of the module's browser area. - void DrawSelf(); + virtual bool HandleInputEvent(const pp::InputEvent& event); -// private: - // Browser connectivity and scripting support. -// ScriptingBridge scripting_bridge_; + void DrawSelf(); - SharedOpenGLContext opengl_context_; + SharedOpenGLContext opengl_context_; ivec2 m_size; }; diff --git a/src/platform/nacl/opengl_context.h b/src/platform/nacl/opengl_context.h index c5d1b91f..95c237ca 100644 --- a/src/platform/nacl/opengl_context.h +++ b/src/platform/nacl/opengl_context.h @@ -61,6 +61,8 @@ class OpenGLContext : public pp::Graphics3DClient { /// Resize the context. void ResizeContext(const pp::Size& size); + pp::Size const& GetSize() { return size_; } + /// The OpenGL ES 2.0 interface. const struct PPB_OpenGLES2* gles2() const { return gles2_interface_; diff --git a/test/tutorial/tut03.cpp b/test/tutorial/tut03.cpp index de451f17..b786c26f 100644 --- a/test/tutorial/tut03.cpp +++ b/test/tutorial/tut03.cpp @@ -80,7 +80,7 @@ public: m_deltascale[i] = 1.0; m_dirty[i] = 2; } -#if defined __CELLOS_LV2__ || defined __native_client__ +#if defined __CELLOS_LV2__ //m_center = f64cmplx(-.22815528839841, -1.11514249704382); //m_center = f64cmplx(0.001643721971153, 0.822467633298876); m_center = f64cmplx(-0.65823419062254, .50221777363480); @@ -178,7 +178,7 @@ public: f64cmplx worldmouse = m_center + ScreenToWorldOffset(mousepos); ivec3 buttons = Input::GetMouseButtons(); -#if !defined __CELLOS_LV2__ && !defined __native_client__ +#if !defined __CELLOS_LV2__ if ((buttons[0] || buttons[2]) && mousepos.x != -1) { double zoom = buttons[0] ? -0.0005 : 0.0005; @@ -210,7 +210,7 @@ public: zoom = 1e-14 / m_radius; } m_radius *= zoom; -#if !defined __CELLOS_LV2__ && !defined __native_client__ +#if !defined __CELLOS_LV2__ m_center = (m_center - worldmouse) * zoom + worldmouse; worldmouse = m_center + ScreenToWorldOffset(mousepos); #endif