summaryrefslogtreecommitdiff
path: root/avmedia
diff options
context:
space:
mode:
authorZolnai Tamás <tamas.zolnai@collabora.com>2014-05-13 00:07:48 +0200
committerZolnai Tamás <tamas.zolnai@collabora.com>2014-05-13 00:09:11 +0200
commitbf703a7ef97008a19b7cd725acd98e3b86889283 (patch)
tree8ee8cf63d7196f70143abcab665293bfa6380316 /avmedia
parent01d3044d30283aec1b7a6908428691a6befe6783 (diff)
glTF rendering: first try to move camera position
SystemChildWindow can't handle events by its own that's why it's parent is used as an event handler. Mouse pointer specify the active model. This patch made for editing, in case of slideshow we have one less window. Change-Id: If8ac57176b9a0abab518f8d8a06a2a41177a4881
Diffstat (limited to 'avmedia')
-rw-r--r--avmedia/source/opengl/oglplayer.cxx2
-rw-r--r--avmedia/source/opengl/oglwindow.cxx87
-rw-r--r--avmedia/source/opengl/oglwindow.hxx7
-rw-r--r--avmedia/source/viewer/mediawindow_impl.cxx20
-rw-r--r--avmedia/source/viewer/mediawindow_impl.hxx1
5 files changed, 105 insertions, 12 deletions
diff --git a/avmedia/source/opengl/oglplayer.cxx b/avmedia/source/opengl/oglplayer.cxx
index f74162bbc5e3..43b8a71ef4ba 100644
--- a/avmedia/source/opengl/oglplayer.cxx
+++ b/avmedia/source/opengl/oglplayer.cxx
@@ -211,7 +211,7 @@ uno::Reference< media::XPlayerWindow > SAL_CALL OGLPlayer::createPlayerWindow( c
m_pHandle->viewport.y = 0;
m_pHandle->viewport.width = aSize.Width();
m_pHandle->viewport.height = aSize.Height();
- OGLWindow* pWindow = new OGLWindow(m_pHandle, &m_aContext);
+ OGLWindow* pWindow = new OGLWindow(m_pHandle, &m_aContext, pChildWindow);
return uno::Reference< media::XPlayerWindow >( pWindow );
}
diff --git a/avmedia/source/opengl/oglwindow.cxx b/avmedia/source/opengl/oglwindow.cxx
index 31688741e639..35b1ab4d4a4f 100644
--- a/avmedia/source/opengl/oglwindow.cxx
+++ b/avmedia/source/opengl/oglwindow.cxx
@@ -14,9 +14,10 @@ using namespace com::sun::star;
namespace avmedia { namespace ogl {
-OGLWindow::OGLWindow( glTFHandle* pHandle, OpenGLContext* pContext )
+OGLWindow::OGLWindow( glTFHandle* pHandle, OpenGLContext* pContext, SystemChildWindow* pChildWindow )
: m_pHandle( pHandle )
, m_pContext( pContext )
+ , m_pEventHandler( pChildWindow->GetParent() )
, m_bVisible ( false )
, meZoomLevel( media::ZoomLevel_ORIGINAL )
{
@@ -122,7 +123,17 @@ void SAL_CALL OGLWindow::setVisible( sal_Bool bSet )
throw (uno::RuntimeException, std::exception)
{
if( bSet && !m_bVisible )
+ {
update();
+ m_pEventHandler->GetParent()->AddEventListener( LINK(this, OGLWindow, FocusGrabber));
+ m_pEventHandler->AddEventListener( LINK(this, OGLWindow, CameraHandler));
+ m_pEventHandler->GrabFocus();
+ }
+ else if( !bSet )
+ {
+ m_pEventHandler->GetParent()->RemoveEventListener( LINK(this, OGLWindow, FocusGrabber));
+ m_pEventHandler->RemoveEventListener( LINK(this, OGLWindow, CameraHandler));
+ }
m_bVisible = bSet;
}
@@ -196,6 +207,80 @@ void SAL_CALL OGLWindow::removePaintListener( const uno::Reference< awt::XPaintL
{
}
+IMPL_LINK(OGLWindow, FocusGrabber, VclWindowEvent*, pEvent)
+{
+ assert(m_pEventHandler);
+ if( pEvent->GetId() == VCLEVENT_WINDOW_MOUSEMOVE )
+ {
+ MouseEvent* pMouseEvt = (MouseEvent*)pEvent->GetData();
+ if(pMouseEvt)
+ {
+ const Point& rMousePos = pMouseEvt->GetPosPixel();
+ const Rectangle aWinRect(m_pEventHandler->GetPosPixel(),m_pEventHandler->GetSizePixel());
+ if( aWinRect.IsInside(rMousePos) )
+ {
+ if ( !m_pEventHandler->HasFocus() )
+ {
+ m_pEventHandler->GrabFocus();
+ }
+ }
+ else if ( m_pEventHandler->HasFocus() )
+ {
+ m_pEventHandler->GrabFocusToDocument();
+ }
+ }
+ }
+
+ return 0;
+}
+
+IMPL_LINK(OGLWindow, CameraHandler, VclWindowEvent*, pEvent)
+{
+ if( pEvent->GetId() == VCLEVENT_WINDOW_KEYINPUT )
+ {
+ KeyEvent* pKeyEvt = (KeyEvent*)pEvent->GetData();
+ if(pKeyEvt)
+ {
+ sal_uInt16 nCode = pKeyEvt->GetKeyCode().GetCode();
+ m_pContext->makeCurrent();
+
+ // Calculate movement
+ glm::vec3 vMoveBy;
+ {
+ glm::vec3 vEye;
+ glm::vec3 vView;
+ glm::vec3 vUp;
+ gltf_get_camera_pos(&vEye,&vView,&vUp);
+ float fModelSize =(float)gltf_get_model_size();
+
+ glm::vec3 vMove = vView-vEye;
+ vMove = glm::normalize(vMove);
+ vMove *= 25.0f;
+ glm::vec3 vStrafe = glm::cross(vView-vEye, vUp);
+ vStrafe = glm::normalize(vStrafe);
+ vStrafe *= 25.0f;
+ glm::vec3 vMup = glm::cross(vView-vEye,glm::vec3(1.f,0.f,0.f) );
+ vMup = glm::normalize(vMup);
+ vMup *= 25.0f;
+
+ if(nCode == KEY_Q)vMoveBy += vMove*(0.1f*fModelSize);
+ if(nCode == KEY_E)vMoveBy -= vMove*(0.1f*fModelSize);
+ if(nCode == KEY_A)vMoveBy -= vStrafe*(0.1f*fModelSize);
+ if(nCode == KEY_D)vMoveBy += vStrafe*(0.1f*fModelSize);
+ if(nCode == KEY_W)vMoveBy -= vMup*(0.1f*fModelSize);
+ if(nCode == KEY_S)vMoveBy += vMup*(0.1f*fModelSize);
+ }
+
+ gltf_renderer_move_camera(vMoveBy.x,vMoveBy.y,vMoveBy.z,10.0);
+ gltf_prepare_renderer(m_pHandle);
+ gltf_renderer(m_pHandle);
+ gltf_complete_renderer();
+ m_pContext->swapBuffers();
+ }
+ }
+ return 0;
+}
+
} // namespace ogl
} // namespace avmedia
diff --git a/avmedia/source/opengl/oglwindow.hxx b/avmedia/source/opengl/oglwindow.hxx
index 95767c04d52c..e7b0d3ab57d3 100644
--- a/avmedia/source/opengl/oglwindow.hxx
+++ b/avmedia/source/opengl/oglwindow.hxx
@@ -19,6 +19,7 @@
#include <libgltf.h>
#include <vcl/opengl/OpenGLContext.hxx>
+#include <vcl/syschild.hxx>
namespace avmedia { namespace ogl {
@@ -26,7 +27,7 @@ class OGLWindow : public ::cppu::WeakImplHelper2 < com::sun::star::media::XPlaye
com::sun::star::lang::XServiceInfo >
{
public:
- OGLWindow( glTFHandle* pHandle, OpenGLContext* pContext );
+ OGLWindow( glTFHandle* pHandle, OpenGLContext* pContext, SystemChildWindow* pChildWindow );
virtual ~OGLWindow();
virtual void SAL_CALL update() throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
@@ -61,8 +62,12 @@ public:
virtual void SAL_CALL removePaintListener( const com::sun::star::uno::Reference< com::sun::star::awt::XPaintListener >& xListener ) throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
private:
+ DECL_LINK( FocusGrabber, VclWindowEvent* );
+ DECL_LINK( CameraHandler, VclWindowEvent* );
+
glTFHandle* m_pHandle;
OpenGLContext* m_pContext;
+ Window* m_pEventHandler;
bool m_bVisible;
com::sun::star::media::ZoomLevel meZoomLevel;
};
diff --git a/avmedia/source/viewer/mediawindow_impl.cxx b/avmedia/source/viewer/mediawindow_impl.cxx
index ab9d35156d3d..6ef84626a037 100644
--- a/avmedia/source/viewer/mediawindow_impl.cxx
+++ b/avmedia/source/viewer/mediawindow_impl.cxx
@@ -162,6 +162,7 @@ MediaWindowImpl::MediaWindowImpl( Window* pParent, MediaWindow* pMediaWindow, bo
DragSourceHelper( this ),
mpMediaWindow( pMediaWindow ),
mpEvents( NULL ),
+ mbEventTransparent(true),
mpMediaWindowControl( bInternalMediaControl ? new MediaWindowControl( this ) : NULL ),
mpEmptyBmpEx( NULL ),
mpAudioBmpEx( NULL )
@@ -505,6 +506,7 @@ void MediaWindowImpl::onURLChanged()
{
SystemWindowData aWinData = OpenGLContext::generateWinData(this);
mpChildWindow.reset(new MediaChildWindow(this,&aWinData));
+ mbEventTransparent = false;
}
if( !mpChildWindow )
return;
@@ -715,7 +717,7 @@ void MediaWindowImpl::GetFocus()
void MediaWindowImpl::MouseMove( const MouseEvent& rMEvt )
{
- if( mpMediaWindow )
+ if( mpMediaWindow && mbEventTransparent )
mpMediaWindow->MouseMove( rMEvt );
}
@@ -723,7 +725,7 @@ void MediaWindowImpl::MouseMove( const MouseEvent& rMEvt )
void MediaWindowImpl::MouseButtonDown( const MouseEvent& rMEvt )
{
- if( mpMediaWindow )
+ if( mpMediaWindow && mbEventTransparent )
mpMediaWindow->MouseButtonDown( rMEvt );
}
@@ -731,7 +733,7 @@ void MediaWindowImpl::MouseButtonDown( const MouseEvent& rMEvt )
void MediaWindowImpl::MouseButtonUp( const MouseEvent& rMEvt )
{
- if( mpMediaWindow )
+ if( mpMediaWindow && mbEventTransparent )
mpMediaWindow->MouseButtonUp( rMEvt );
}
@@ -739,7 +741,7 @@ void MediaWindowImpl::MouseButtonUp( const MouseEvent& rMEvt )
void MediaWindowImpl::KeyInput( const KeyEvent& rKEvt )
{
- if( mpMediaWindow )
+ if( mpMediaWindow && mbEventTransparent )
mpMediaWindow->KeyInput( rKEvt );
}
@@ -747,7 +749,7 @@ void MediaWindowImpl::KeyInput( const KeyEvent& rKEvt )
void MediaWindowImpl::KeyUp( const KeyEvent& rKEvt )
{
- if( mpMediaWindow )
+ if( mpMediaWindow && mbEventTransparent )
mpMediaWindow->KeyUp( rKEvt );
}
@@ -755,7 +757,7 @@ void MediaWindowImpl::KeyUp( const KeyEvent& rKEvt )
void MediaWindowImpl::Command( const CommandEvent& rCEvt )
{
- if( mpMediaWindow )
+ if( mpMediaWindow && mbEventTransparent )
mpMediaWindow->Command( rCEvt );
}
@@ -763,21 +765,21 @@ void MediaWindowImpl::Command( const CommandEvent& rCEvt )
sal_Int8 MediaWindowImpl::AcceptDrop( const AcceptDropEvent& rEvt )
{
- return( mpMediaWindow ? mpMediaWindow->AcceptDrop( rEvt ) : 0 );
+ return( mpMediaWindow && mbEventTransparent ? mpMediaWindow->AcceptDrop( rEvt ) : 0 );
}
sal_Int8 MediaWindowImpl::ExecuteDrop( const ExecuteDropEvent& rEvt )
{
- return( mpMediaWindow ? mpMediaWindow->ExecuteDrop( rEvt ) : 0 );
+ return( mpMediaWindow && mbEventTransparent ? mpMediaWindow->ExecuteDrop( rEvt ) : 0 );
}
void MediaWindowImpl::StartDrag( sal_Int8 nAction, const Point& rPosPixel )
{
- if( mpMediaWindow )
+ if( mpMediaWindow && mbEventTransparent )
mpMediaWindow->StartDrag( nAction, rPosPixel );
}
diff --git a/avmedia/source/viewer/mediawindow_impl.hxx b/avmedia/source/viewer/mediawindow_impl.hxx
index 906959d0c429..a5e8215d0d90 100644
--- a/avmedia/source/viewer/mediawindow_impl.hxx
+++ b/avmedia/source/viewer/mediawindow_impl.hxx
@@ -174,6 +174,7 @@ namespace avmedia
::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > mxEventsIf;
MediaEventListenersImpl* mpEvents;
+ bool mbEventTransparent;
boost::scoped_ptr<MediaChildWindow> mpChildWindow;
MediaWindowControl* mpMediaWindowControl;
BitmapEx* mpEmptyBmpEx;