1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <vcl/openglwin.hxx>
11 #include <vcl/opengl/OpenGLContext.hxx>
12 #include <vcl/event.hxx>
13 #include <vcl/sysdata.hxx>
15 class OpenGLWindowImpl
18 explicit OpenGLWindowImpl(vcl::Window
* pWindow
, bool bInit
);
20 OpenGLContext
& getContext() { return *mxContext
.get(); }
22 bool IsInitialized() const;
28 rtl::Reference
<OpenGLContext
> mxContext
;
29 VclPtr
<SystemChildWindow
> mxChildWindow
;
34 OpenGLWindowImpl::OpenGLWindowImpl(vcl::Window
* pWindow
, bool bInit
)
35 : mxContext(OpenGLContext::Create()),
38 SystemWindowData aData
= mxContext
->generateWinData(pWindow
, false);
39 mxChildWindow
.reset(VclPtr
<SystemChildWindow
>::Create(pWindow
, 0, &aData
));
40 mxChildWindow
->Show();
43 mxContext
->init(mxChildWindow
.get());
45 pWindow
->SetMouseTransparent(false);
48 OpenGLWindowImpl::~OpenGLWindowImpl()
51 mxChildWindow
.disposeAndClear();
54 bool OpenGLWindowImpl::IsInitialized() const
59 void OpenGLWindowImpl::Initialize()
61 mxContext
->init(mxChildWindow
.get());
65 OpenGLWindow::OpenGLWindow(vcl::Window
* pParent
, bool bInit
):
67 mxImpl(new OpenGLWindowImpl(this, bInit
)),
72 OpenGLWindow::~OpenGLWindow()
77 void OpenGLWindow::dispose()
80 mpRenderer
->contextDestroyed();
86 OpenGLContext
& OpenGLWindow::getContext()
88 return mxImpl
->getContext();
91 void OpenGLWindow::Paint(vcl::RenderContext
& /*rRenderContext*/, const Rectangle
&)
97 void OpenGLWindow::MouseButtonDown( const MouseEvent
& rMEvt
)
99 maStartPoint
= rMEvt
.GetPosPixel();
102 void OpenGLWindow::MouseButtonUp( const MouseEvent
& rMEvt
)
107 Point aPoint
= rMEvt
.GetPosPixel();
108 if(aPoint
== maStartPoint
)
110 mpRenderer
->clickedAt(aPoint
, rMEvt
.GetButtons());
114 mpRenderer
->mouseDragMove(maStartPoint
, aPoint
,
119 void OpenGLWindow::Command( const CommandEvent
& rCEvt
)
124 if(rCEvt
.GetCommand() == CommandEventId::Wheel
)
126 const CommandWheelData
* pData
= rCEvt
.GetWheelData();
127 if(pData
->GetMode() == CommandWheelMode::SCROLL
)
129 long nDelta
= pData
->GetDelta();
130 mpRenderer
->scroll(nDelta
);
135 void OpenGLWindow::MouseMove( const MouseEvent
& /*rMEvt*/ )
139 void OpenGLWindow::setRenderer(IRenderer
* pRenderer
)
141 mpRenderer
= pRenderer
;
144 void OpenGLWindow::Initialize()
146 if (!mxImpl
->IsInitialized())
147 mxImpl
->Initialize();
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */