fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / slideshow / source / engine / OGLTrans / generic / OGLTrans_TransitionImpl.hxx
blobb23f76818c95a46fbb40244a4abfe2ea61804a5d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2008 by Sun Microsystems, Inc.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
28 #ifndef INCLUDED_OGLTRANS_TRANSITIONIMPL_HXX_
29 #define INCLUDED_OGLTRANS_TRANSITIONIMPL_HXX_
31 #include <config_lgpl.h>
32 #include <glm/glm.hpp>
34 #include <boost/noncopyable.hpp>
35 #include <boost/shared_ptr.hpp>
37 #include <GL/glew.h>
39 #include <basegfx/vector/b2dvector.hxx>
40 #include <basegfx/vector/b3dvector.hxx>
42 #include <vector>
44 class Primitive;
45 class Operation;
46 class SceneObject;
47 class TransitionData;
49 struct TransitionSettings
51 TransitionSettings() :
52 mbUseMipMapLeaving( true ),
53 mbUseMipMapEntering( true ),
54 mnRequiredGLVersion( 1.0 ),
55 mbReflectSlides( false )
59 /** Whether to use mipmaping for slides textures
61 bool mbUseMipMapLeaving;
62 bool mbUseMipMapEntering;
64 /** which GL version does the transition require
66 float mnRequiredGLVersion;
68 /** Whether to reflect slides, the reflection happens on flat surface beneath the slides.
69 ** Now it only works with slides which keep their rectangular shape together.
71 bool mbReflectSlides;
74 typedef std::vector<Primitive> Primitives_t;
75 typedef std::vector<boost::shared_ptr<SceneObject> > SceneObjects_t;
76 typedef std::vector<boost::shared_ptr<Operation> > Operations_t;
78 class TransitionScene
80 public:
81 TransitionScene()
85 TransitionScene(
86 const Primitives_t& rLeavingSlidePrimitives,
87 const Primitives_t& rEnteringSlidePrimitives,
88 const Operations_t& rOverallOperations = Operations_t(),
89 const SceneObjects_t& rSceneObjects = SceneObjects_t()
91 : maLeavingSlidePrimitives(rLeavingSlidePrimitives)
92 , maEnteringSlidePrimitives(rEnteringSlidePrimitives)
93 , maOverallOperations(rOverallOperations)
94 , maSceneObjects(rSceneObjects)
98 TransitionScene(TransitionScene const& rOther);
99 TransitionScene& operator=(const TransitionScene& rOther);
101 void swap(TransitionScene& rOther);
103 const Primitives_t& getLeavingSlide() const
105 return maLeavingSlidePrimitives;
108 const Primitives_t& getEnteringSlide() const
110 return maEnteringSlidePrimitives;
113 const Operations_t& getOperations() const
115 return maOverallOperations;
118 const SceneObjects_t& getSceneObjects() const
120 return maSceneObjects;
123 private:
124 /** All the primitives that use the leaving slide texture
126 Primitives_t maLeavingSlidePrimitives;
128 /** All the primitives that use the leaving slide texture
130 Primitives_t maEnteringSlidePrimitives;
132 /** All the operations that should be applied to both leaving and entering slide primitives. These operations will be called in the order they were pushed back in. In OpenGL this effectively uses the operations in the opposite order they were pushed back.
134 Operations_t maOverallOperations;
136 /** All the surrounding scene objects
138 SceneObjects_t maSceneObjects;
141 /** OpenGL 3D Transition class. It implicitly is constructed from XOGLTransition
143 It holds Primitives and Operations on those primitives.
145 class OGLTransitionImpl : private boost::noncopyable
147 public:
148 virtual ~OGLTransitionImpl();
150 /** Prepare transition.
152 void prepare( ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex );
153 /** Display a step of the transition.
155 void display( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight );
156 /** Clean up after transition.
158 void finish();
160 TransitionSettings const& getSettings() const
162 return maSettings;
165 protected:
166 OGLTransitionImpl(const TransitionScene& rScene, const TransitionSettings& rSettings)
167 : maScene(rScene)
168 , maSettings(rSettings)
171 OGLTransitionImpl() {}
173 TransitionScene const& getScene() const
175 return maScene;
178 void setScene(TransitionScene const& rScene);
179 // void setSettings(TransitionSettings const& rSettings);
181 void displaySlide( double nTime, ::sal_Int32 glSlideTex, const Primitives_t& primitives, double SlideWidthScale, double SlideHeightScale );
182 void displayScene( double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight);
183 void applyOverallOperations( double nTime, double SlideWidthScale, double SlideHeightScale );
185 private:
186 /** This function is called in display method to prepare the slides, scene, etc.
188 * Default implementation does nothing.
190 virtual void prepare( double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight );
192 /** This function is called after glx context is ready to let the transition prepare GL related things, like GLSL program.
194 * Default implementation does nothing.
196 virtual void prepareTransition( ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex );
198 /** This function is called when the transition needs to clear after itself, like delete own textures etc.
200 * Default implementation does nothing.
202 virtual void finishTransition();
204 /** This function is called in display method to display the slides.
206 * Default implementation applies overall operations and then
207 * displays both slides.
209 virtual void displaySlides_( double nTime, ::sal_Int32 glLeavingSlideTex, ::sal_Int32 glEnteringSlideTex, double SlideWidthScale, double SlideHeightScale );
211 private:
212 TransitionScene maScene;
213 const TransitionSettings maSettings;
217 // "Constructors" of available transitions
218 boost::shared_ptr<OGLTransitionImpl> makeOutsideCubeFaceToLeft();
219 boost::shared_ptr<OGLTransitionImpl> makeInsideCubeFaceToLeft();
220 boost::shared_ptr<OGLTransitionImpl> makeNByMTileFlip( ::sal_uInt16 n, ::sal_uInt16 m );
221 boost::shared_ptr<OGLTransitionImpl> makeRevolvingCircles( ::sal_uInt16 nCircles , ::sal_uInt16 nPointsOnCircles );
222 boost::shared_ptr<OGLTransitionImpl> makeHelix( ::sal_uInt16 nRows );
223 boost::shared_ptr<OGLTransitionImpl> makeFallLeaving();
224 boost::shared_ptr<OGLTransitionImpl> makeTurnAround();
225 boost::shared_ptr<OGLTransitionImpl> makeTurnDown();
226 boost::shared_ptr<OGLTransitionImpl> makeIris();
227 boost::shared_ptr<OGLTransitionImpl> makeRochade();
228 boost::shared_ptr<OGLTransitionImpl> makeVenetianBlinds( bool vertical, int parts );
229 boost::shared_ptr<OGLTransitionImpl> makeStatic();
230 boost::shared_ptr<OGLTransitionImpl> makeDissolve();
231 boost::shared_ptr<OGLTransitionImpl> makeNewsflash();
233 /** 2D replacements
235 boost::shared_ptr<OGLTransitionImpl> makeDiamond();
236 boost::shared_ptr<OGLTransitionImpl> makeFadeSmoothly();
237 boost::shared_ptr<OGLTransitionImpl> makeFadeThroughBlack();
239 class SceneObject : private boost::noncopyable
241 public:
242 SceneObject();
243 virtual ~SceneObject();
245 virtual void prepare() {}
246 virtual void display(double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight) const;
247 virtual void finish() {}
249 void pushPrimitive (const Primitive &p);
251 protected:
252 /** All the surrounding scene primitives
254 Primitives_t maPrimitives;
257 class Iris : public SceneObject
259 public:
260 Iris ();
262 virtual void prepare() SAL_OVERRIDE;
263 virtual void display(double nTime, double SlideWidth, double SlideHeight, double DispWidth, double DispHeight) const SAL_OVERRIDE;
264 virtual void finish() SAL_OVERRIDE;
266 private:
267 GLuint maTexture;
270 /** This class is a list of Triangles that will share Operations, and could possibly share
272 class Primitive
274 public:
275 Primitive() {}
276 // making copy constructor explicit makes the class un-suitable for use with stl containers
277 Primitive(const Primitive& rvalue);
278 Primitive& operator=(const Primitive& rvalue);
280 void swap(Primitive& rOther);
282 void applyOperations(double nTime, double SlideWidthScale, double SlideHeightScale) const;
283 void display(double nTime, double SlideWidthScale, double SlideHeightScale) const;
285 /** PushBack a vertex,normal, and tex coord. Each SlideLocation is where on the slide is mapped to this location ( from (0,0) to (1,1) ). This will make sure the correct aspect ratio is used, and helps to make slides begin and end at the correct position. (0,0) is the top left of the slide, and (1,1) is the bottom right.
287 @param SlideLocation0
288 Location of first Vertex on slide
290 @param SlideLocation1
291 Location of second Vertex on slide
293 @param SlideLocation2
294 Location of third Vertex on slide
297 void pushTriangle(const glm::vec2& SlideLocation0,const glm::vec2& SlideLocation1,const glm::vec2& SlideLocation2);
299 /** clear all the vertices, normals, tex coordinates, and normals
301 void clearTriangles();
303 /** guards against directly changing the vertices
305 @return
306 the list of vertices
308 const std::vector<glm::vec3>& getVertices() const {return Vertices;}
310 /** guards against directly changing the vertices
312 const std::vector<glm::vec3>& getNormals() const {return Normals;}
314 /** guards against directly changing the vertices
316 @return
317 the list of Texture Coordinates
320 const std::vector<glm::vec2>& getTexCoords() const {return TexCoords;}
322 /** list of Operations to be performed on this primitive.These operations will be called in the order they were pushed back in. In OpenGL this effectively uses the operations in the opposite order they were pushed back.
324 @return
325 the list of Operations
328 Operations_t Operations;
330 private:
331 /** list of vertices
333 std::vector<glm::vec3> Vertices;
335 /** list of Normals
337 std::vector<glm::vec3> Normals;
339 /** list of Texture Coordinates
341 std::vector<glm::vec2> TexCoords;
344 /** This class is to be derived to make any operation (transform) you may need in order to construct your transitions
346 class Operation : private boost::noncopyable
348 public:
349 virtual ~Operation(){}
351 protected:
352 /** Should this operation be interpolated . If TRUE, the transform will smoothly move from making no difference from t = 0.0 to mnT0 to being completely transformed from t = mnT1 to 1. If FALSE, the transform will be inneffectual from t = 0 to mnT0, and completely transformed from t = mnT0 to 1.
354 bool mbInterpolate;
356 /** time to begin the transformation
358 double mnT0;
360 /** time to finish the transformation
362 double mnT1;
363 public:
364 /** this is the function that is called to give the Operation to OpenGL.
366 @param t
367 time from t = 0 to t = 1
369 @param SlideWidthScale
370 width of slide divided by width of window
372 @param SlideHeightScale
373 height of slide divided by height of window
376 virtual void interpolate(double t,double SlideWidthScale,double SlideHeightScale) const = 0;
378 protected:
379 Operation(bool bInterpolate, double nT0, double nT1):
380 mbInterpolate(bInterpolate), mnT0(nT0), mnT1(nT1){}
383 /** this class is a generic CounterClockWise(CCW) rotation with an axis angle
385 class SRotate: public Operation
387 public:
388 virtual void interpolate(double t,double SlideWidthScale,double SlideHeightScale) const SAL_OVERRIDE;
390 /** Constructor
392 @param Axis
393 axis to rotate about
395 @param Origin
396 position that rotation axis runs through
398 @param Angle
399 angle in radians of CCW rotation
401 @param bInter
402 see Operation
404 @param T0
405 transformation starting time
407 @param T1
408 transformation ending time
411 SRotate(const glm::vec3& Axis, const glm::vec3& Origin, double Angle,
412 bool bInter, double T0, double T1);
413 virtual ~SRotate(){}
414 private:
415 /** axis to rotate CCW about
417 glm::vec3 axis;
419 /** position that rotation axis runs through
421 glm::vec3 origin;
423 /** angle in radians of CCW rotation
425 double angle;
428 boost::shared_ptr<SRotate>
429 makeSRotate(const glm::vec3& Axis, const glm::vec3& Origin, double Angle,
430 bool bInter, double T0, double T1);
432 /** scaling transformation
434 class SScale: public Operation
436 public:
437 virtual void interpolate(double t,double SlideWidthScale,double SlideHeightScale) const SAL_OVERRIDE;
439 /** Constructor
441 @param Scale
442 amount to scale by
444 @param Origin
445 position that rotation axis runs through
447 @param bInter
448 see Operation
450 @param T0
451 transformation starting time
453 @param T1
454 transformation ending time
457 SScale(const glm::vec3& Scale, const glm::vec3& Origin,bool bInter, double T0, double T1);
458 virtual ~SScale(){}
459 private:
460 glm::vec3 scale;
461 glm::vec3 origin;
464 boost::shared_ptr<SScale>
465 makeSScale(const glm::vec3& Scale, const glm::vec3& Origin,bool bInter, double T0, double T1);
467 /** translation transformation
469 class STranslate: public Operation
471 public:
472 virtual void interpolate(double t,double SlideWidthScale,double SlideHeightScale) const SAL_OVERRIDE;
474 /** Constructor
476 @param Vector
477 vector to translate
479 @param bInter
480 see Operation
482 @param T0
483 transformation starting time
485 @param T1
486 transformation ending time
489 STranslate(const glm::vec3& Vector,bool bInter, double T0, double T1);
490 virtual ~STranslate(){}
491 private:
492 /** vector to translate by
494 glm::vec3 vector;
497 boost::shared_ptr<STranslate>
498 makeSTranslate(const glm::vec3& Vector,bool bInter, double T0, double T1);
500 /** translation transformation
502 class SEllipseTranslate: public Operation
504 public:
505 virtual void interpolate(double t,double SlideWidthScale,double SlideHeightScale) const SAL_OVERRIDE;
507 /** Constructor
509 @param Vector
510 vector to translate
512 @param bInter
513 see Operation
515 @param T0
516 transformation starting time
518 @param T1
519 transformation ending time
522 SEllipseTranslate(double dWidth, double dHeight, double dStartPosition, double dEndPosition, bool bInter, double T0, double T1);
523 virtual ~SEllipseTranslate(){}
524 private:
525 /** width and length of the ellipse
527 double width, height;
529 /** start and end position on the ellipse <0,1>
531 double startPosition;
532 double endPosition;
535 boost::shared_ptr<SEllipseTranslate>
536 makeSEllipseTranslate(double dWidth, double dHeight, double dStartPosition, double dEndPosition, bool bInter, double T0, double T1);
538 /** Same as SRotate, except the depth is scaled by the width of the slide divided by the width of the window.
540 class RotateAndScaleDepthByWidth: public Operation
542 public:
543 virtual void interpolate(double t,double SlideWidthScale,double SlideHeightScale) const SAL_OVERRIDE;
545 RotateAndScaleDepthByWidth(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1);
546 virtual ~RotateAndScaleDepthByWidth(){}
547 private:
548 glm::vec3 axis;
549 glm::vec3 origin;
550 double angle;
553 boost::shared_ptr<RotateAndScaleDepthByWidth>
554 makeRotateAndScaleDepthByWidth(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1);
556 /** Same as SRotate, except the depth is scaled by the width of the slide divided by the height of the window.
558 class RotateAndScaleDepthByHeight: public Operation
560 public:
561 virtual void interpolate(double t,double SlideWidthScale,double SlideHeightScale) const SAL_OVERRIDE;
563 RotateAndScaleDepthByHeight(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1);
564 virtual ~RotateAndScaleDepthByHeight(){}
565 private:
566 glm::vec3 axis;
567 glm::vec3 origin;
568 double angle;
571 boost::shared_ptr<RotateAndScaleDepthByHeight>
572 makeRotateAndScaleDepthByHeight(const glm::vec3& Axis,const glm::vec3& Origin,double Angle,bool bInter, double T0, double T1);
574 #endif // INCLUDED_SLIDESHOW_TRANSITION_HXX_
576 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */