2014-05-07 03:45:41 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <vcl/openglwin.hxx>
|
2014-05-07 04:16:54 +02:00
|
|
|
#include <vcl/opengl/OpenGLContext.hxx>
|
2014-05-10 08:24:54 +02:00
|
|
|
#include <vcl/event.hxx>
|
2014-09-02 01:01:37 +02:00
|
|
|
#include <vcl/sysdata.hxx>
|
2014-05-07 04:16:54 +02:00
|
|
|
|
|
|
|
class OpenGLWindowImpl
|
|
|
|
{
|
|
|
|
public:
|
2014-09-23 11:20:40 +02:00
|
|
|
OpenGLWindowImpl(vcl::Window* pWindow);
|
2015-04-22 17:19:42 +01:00
|
|
|
~OpenGLWindowImpl() { mxChildWindow.disposeAndClear(); }
|
2014-06-18 12:14:29 +02:00
|
|
|
OpenGLContext& getContext() { return maContext;}
|
2014-05-07 04:16:54 +02:00
|
|
|
private:
|
|
|
|
OpenGLContext maContext;
|
2015-03-13 16:26:50 +02:00
|
|
|
VclPtr<SystemChildWindow> mxChildWindow;
|
2014-05-07 04:16:54 +02:00
|
|
|
};
|
|
|
|
|
2014-09-23 11:20:40 +02:00
|
|
|
OpenGLWindowImpl::OpenGLWindowImpl(vcl::Window* pWindow)
|
2014-05-07 04:16:54 +02:00
|
|
|
{
|
2014-09-02 01:01:37 +02:00
|
|
|
SystemWindowData aData = OpenGLContext::generateWinData(pWindow, false);
|
2015-04-20 15:35:54 +01:00
|
|
|
mxChildWindow.reset(VclPtr<SystemChildWindow>::Create(pWindow, 0, &aData));
|
2015-02-15 20:41:33 +00:00
|
|
|
mxChildWindow->Show();
|
|
|
|
maContext.init(mxChildWindow.get());
|
2014-05-15 10:55:02 +02:00
|
|
|
pWindow->SetMouseTransparent(false);
|
2014-05-07 04:16:54 +02:00
|
|
|
}
|
|
|
|
|
2014-09-23 11:20:40 +02:00
|
|
|
OpenGLWindow::OpenGLWindow(vcl::Window* pParent):
|
2014-05-28 17:31:27 +02:00
|
|
|
Window(pParent, 0),
|
2015-02-15 20:41:33 +00:00
|
|
|
mxImpl(new OpenGLWindowImpl(this)),
|
2014-05-13 05:12:55 +02:00
|
|
|
mpRenderer(NULL)
|
2014-05-07 04:16:54 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenGLWindow::~OpenGLWindow()
|
2015-01-09 15:26:08 +00:00
|
|
|
{
|
2015-03-10 09:07:06 +02:00
|
|
|
disposeOnce();
|
2015-01-09 15:26:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLWindow::dispose()
|
2014-05-07 03:45:41 +02:00
|
|
|
{
|
2014-05-23 01:19:19 +02:00
|
|
|
if(mpRenderer)
|
|
|
|
mpRenderer->contextDestroyed();
|
2015-01-09 15:26:08 +00:00
|
|
|
mpRenderer = NULL;
|
2015-04-22 17:19:42 +01:00
|
|
|
mxImpl.reset();
|
2015-01-09 15:26:08 +00:00
|
|
|
Window::dispose();
|
2014-05-07 03:45:41 +02:00
|
|
|
}
|
|
|
|
|
2014-06-18 12:14:29 +02:00
|
|
|
OpenGLContext& OpenGLWindow::getContext()
|
2014-05-07 03:45:41 +02:00
|
|
|
{
|
2015-02-15 20:41:33 +00:00
|
|
|
return mxImpl->getContext();
|
2014-05-07 03:45:41 +02:00
|
|
|
}
|
|
|
|
|
2014-05-13 05:12:55 +02:00
|
|
|
void OpenGLWindow::Paint(const Rectangle&)
|
|
|
|
{
|
|
|
|
if(mpRenderer)
|
|
|
|
mpRenderer->update();
|
|
|
|
}
|
|
|
|
|
2014-05-10 08:24:54 +02:00
|
|
|
void OpenGLWindow::MouseButtonDown( const MouseEvent& rMEvt )
|
|
|
|
{
|
2014-05-24 23:28:06 +02:00
|
|
|
maStartPoint = rMEvt.GetPosPixel();
|
|
|
|
}
|
2014-05-10 08:24:54 +02:00
|
|
|
|
2014-05-24 23:28:06 +02:00
|
|
|
void OpenGLWindow::MouseButtonUp( const MouseEvent& rMEvt )
|
|
|
|
{
|
2014-06-01 17:10:42 +02:00
|
|
|
if(!mpRenderer)
|
|
|
|
return;
|
|
|
|
|
2014-05-24 23:28:06 +02:00
|
|
|
Point aPoint = rMEvt.GetPosPixel();
|
|
|
|
if(aPoint == maStartPoint)
|
|
|
|
{
|
2014-06-01 17:10:42 +02:00
|
|
|
mpRenderer->clickedAt(aPoint, rMEvt.GetButtons());
|
2014-05-24 23:28:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mpRenderer->mouseDragMove(maStartPoint, aPoint,
|
|
|
|
rMEvt.GetButtons());
|
|
|
|
}
|
2014-05-10 08:24:54 +02:00
|
|
|
}
|
|
|
|
|
2014-05-24 23:28:06 +02:00
|
|
|
void OpenGLWindow::Command( const CommandEvent& rCEvt )
|
2014-05-24 16:43:05 +01:00
|
|
|
{
|
2014-06-01 17:10:42 +02:00
|
|
|
if(!mpRenderer)
|
|
|
|
return;
|
|
|
|
|
2014-05-24 23:28:06 +02:00
|
|
|
if(rCEvt.GetCommand() == COMMAND_WHEEL)
|
|
|
|
{
|
|
|
|
const CommandWheelData* pData = rCEvt.GetWheelData();
|
2014-10-31 07:26:39 +02:00
|
|
|
if(pData->GetMode() == CommandWheelMode::SCROLL)
|
2014-05-24 23:28:06 +02:00
|
|
|
{
|
|
|
|
long nDelta = pData->GetDelta();
|
2014-06-01 17:10:42 +02:00
|
|
|
mpRenderer->scroll(nDelta);
|
2014-05-24 23:28:06 +02:00
|
|
|
}
|
|
|
|
}
|
2014-05-24 16:43:05 +01:00
|
|
|
}
|
|
|
|
|
2014-05-24 23:28:06 +02:00
|
|
|
void OpenGLWindow::MouseMove( const MouseEvent& /*rMEvt*/ )
|
2014-05-24 16:43:05 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-13 05:12:55 +02:00
|
|
|
void OpenGLWindow::setRenderer(IRenderer* pRenderer)
|
|
|
|
{
|
|
|
|
mpRenderer = pRenderer;
|
|
|
|
}
|
|
|
|
|
2014-05-07 03:45:41 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|