@@ -17,6 +17,7 @@ | |||||
#include <ppapi/cpp/var.h> | #include <ppapi/cpp/var.h> | ||||
#include <ppapi/cpp/module.h> | #include <ppapi/cpp/module.h> | ||||
#include <ppapi/cpp/completion_callback.h> | #include <ppapi/cpp/completion_callback.h> | ||||
#include <ppapi/cpp/input_event.h> | |||||
#include "core.h" | #include "core.h" | ||||
#include "debug/quad.h" | #include "debug/quad.h" | ||||
@@ -31,7 +32,7 @@ NaClInstance::NaClInstance(PP_Instance instance) | |||||
: pp::Instance(instance), | : pp::Instance(instance), | ||||
m_size(0, 0) | m_size(0, 0) | ||||
{ | { | ||||
; | |||||
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); | |||||
} | } | ||||
NaClInstance::~NaClInstance() | NaClInstance::~NaClInstance() | ||||
@@ -101,6 +102,25 @@ void NaClInstance::DidChangeView(const pp::Rect& position, const pp::Rect& clip) | |||||
DrawSelf(); | 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() | void NaClInstance::DrawSelf() | ||||
{ | { | ||||
if (opengl_context_ == NULL) | if (opengl_context_ == NULL) | ||||
@@ -36,14 +36,13 @@ class NaClInstance : public pp::Instance { | |||||
// Bind and publish the module's methods to JavaScript. | // Bind and publish the module's methods to JavaScript. | ||||
//void InitializeMethods(ScriptingBridge* bridge); | //void InitializeMethods(ScriptingBridge* bridge); | ||||
// Called to draw the contents of the module's browser area. | // 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; | ivec2 m_size; | ||||
}; | }; | ||||
@@ -61,6 +61,8 @@ class OpenGLContext : public pp::Graphics3DClient { | |||||
/// Resize the context. | /// Resize the context. | ||||
void ResizeContext(const pp::Size& size); | void ResizeContext(const pp::Size& size); | ||||
pp::Size const& GetSize() { return size_; } | |||||
/// The OpenGL ES 2.0 interface. | /// The OpenGL ES 2.0 interface. | ||||
const struct PPB_OpenGLES2* gles2() const { | const struct PPB_OpenGLES2* gles2() const { | ||||
return gles2_interface_; | return gles2_interface_; | ||||
@@ -80,7 +80,7 @@ public: | |||||
m_deltascale[i] = 1.0; | m_deltascale[i] = 1.0; | ||||
m_dirty[i] = 2; | m_dirty[i] = 2; | ||||
} | } | ||||
#if defined __CELLOS_LV2__ || defined __native_client__ | |||||
#if defined __CELLOS_LV2__ | |||||
//m_center = f64cmplx(-.22815528839841, -1.11514249704382); | //m_center = f64cmplx(-.22815528839841, -1.11514249704382); | ||||
//m_center = f64cmplx(0.001643721971153, 0.822467633298876); | //m_center = f64cmplx(0.001643721971153, 0.822467633298876); | ||||
m_center = f64cmplx(-0.65823419062254, .50221777363480); | m_center = f64cmplx(-0.65823419062254, .50221777363480); | ||||
@@ -178,7 +178,7 @@ public: | |||||
f64cmplx worldmouse = m_center + ScreenToWorldOffset(mousepos); | f64cmplx worldmouse = m_center + ScreenToWorldOffset(mousepos); | ||||
ivec3 buttons = Input::GetMouseButtons(); | ivec3 buttons = Input::GetMouseButtons(); | ||||
#if !defined __CELLOS_LV2__ && !defined __native_client__ | |||||
#if !defined __CELLOS_LV2__ | |||||
if ((buttons[0] || buttons[2]) && mousepos.x != -1) | if ((buttons[0] || buttons[2]) && mousepos.x != -1) | ||||
{ | { | ||||
double zoom = buttons[0] ? -0.0005 : 0.0005; | double zoom = buttons[0] ? -0.0005 : 0.0005; | ||||
@@ -210,7 +210,7 @@ public: | |||||
zoom = 1e-14 / m_radius; | zoom = 1e-14 / m_radius; | ||||
} | } | ||||
m_radius *= zoom; | m_radius *= zoom; | ||||
#if !defined __CELLOS_LV2__ && !defined __native_client__ | |||||
#if !defined __CELLOS_LV2__ | |||||
m_center = (m_center - worldmouse) * zoom + worldmouse; | m_center = (m_center - worldmouse) * zoom + worldmouse; | ||||
worldmouse = m_center + ScreenToWorldOffset(mousepos); | worldmouse = m_center + ScreenToWorldOffset(mousepos); | ||||
#endif | #endif | ||||