1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include <canvas/debug.hxx>
#include <tools/diagnose_ex.h>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/tools/canvastools.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>
#include <cppcanvas/basegfxfactory.hxx>
#include <comphelper/optional.hxx>
#include <comphelper/make_shared_from_uno.hxx>
#include <com/sun/star/rendering/XIntegerBitmap.hpp>
#include <com/sun/star/rendering/IntegerBitmapLayout.hpp>
#include <com/sun/star/animations/TransitionType.hpp>
#include <com/sun/star/animations/TransitionSubType.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include "slidechangebase.hxx"
#include "transitionfactory.hxx"
#include "transitiontools.hxx"
#include "parametricpolypolygonfactory.hxx"
#include "animationfactory.hxx"
#include "clippingfunctor.hxx"
#include "combtransition.hxx"
#include "tools.hxx"
#include <boost/bind.hpp>
/***************************************************
*** ***
*** Slide Transition Effects ***
*** ***
***************************************************/
using namespace com::sun::star;
namespace slideshow {
namespace internal {
namespace {
// helper methods
// =============================================
void fillPage( const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
const ::basegfx::B2DSize& rPageSizePixel,
const RGBColor& rFillColor )
{
// need to render without any transformation (we
// assume rPageSizePixel to represent device units)
const ::cppcanvas::CanvasSharedPtr pDevicePixelCanvas(
rDestinationCanvas->clone() );
pDevicePixelCanvas->setTransformation( ::basegfx::B2DHomMatrix() );
// TODO(F2): Properly respect clip here.
// Might have to be transformed, too.
const ::basegfx::B2DHomMatrix aViewTransform(
rDestinationCanvas->getTransformation() );
const ::basegfx::B2DPoint aOutputPosPixel(
aViewTransform * ::basegfx::B2DPoint() );
fillRect( pDevicePixelCanvas,
::basegfx::B2DRectangle(
aOutputPosPixel.getX(),
aOutputPosPixel.getY(),
aOutputPosPixel.getX() + rPageSizePixel.getX(),
aOutputPosPixel.getY() + rPageSizePixel.getY() ),
rFillColor.getIntegerColor() );
}
class PluginSlideChange: public SlideChangeBase
{
struct TransitionViewPair {
uno::Reference<presentation::XTransition> mxTransition;
UnoViewSharedPtr mpView;
TransitionViewPair( uno::Reference<presentation::XTransition> xTransition, const UnoViewSharedPtr pView )
{
mxTransition = xTransition;
mpView = pView;
}
~TransitionViewPair()
{
mxTransition.clear();
mpView.reset();;
}
void update( double t )
{
mxTransition->update( t );
}
};
public:
/** Create a new SlideChanger, for the given leaving and
entering slide bitmaps, which uses super secret OpenGL
stuff.
*/
PluginSlideChange( sal_Int16 nTransitionType,
sal_Int16 nTransitionSubType,
boost::optional<SlideSharedPtr> const& leavingSlide_,
const SlideSharedPtr& pEnteringSlide,
const UnoViewContainer& rViewContainer,
ScreenUpdater& rScreenUpdater,
const uno::Reference<
presentation::XTransitionFactory>& xFactory,
const SoundPlayerSharedPtr& pSoundPlayer,
EventMultiplexer& rEventMultiplexer) :
SlideChangeBase( leavingSlide_,
pEnteringSlide,
pSoundPlayer,
rViewContainer,
rScreenUpdater,
rEventMultiplexer ),
maTransitions(),
mbSuccess( false ),
mnTransitionType( nTransitionType ),
mnTransitionSubType( nTransitionSubType ),
mxFactory( xFactory )
{
// create one transition per view
UnoViewVector::const_iterator aCurrView (rViewContainer.begin());
const UnoViewVector::const_iterator aEnd(rViewContainer.end());
while( aCurrView != aEnd )
{
if(! addTransition( *aCurrView ) )
return;
ENSURE_OR_THROW(maTransitions.back() && maTransitions.back()->mxTransition.is(),
"Failed to create plugin transition");
++aCurrView;
}
mbSuccess = true;
}
~PluginSlideChange()
{
mxFactory.clear();
::std::vector< TransitionViewPair* >::const_iterator aCurrView (maTransitions.begin());
::std::vector< TransitionViewPair* >::const_iterator aEnd(maTransitions.end());
while( aCurrView != aEnd )
{
delete (*aCurrView);
++aCurrView;
}
maTransitions.clear();
}
bool addTransition( const UnoViewSharedPtr& rView )
{
uno::Reference<presentation::XTransition> rTransition = mxFactory->createTransition(
mnTransitionType,
mnTransitionSubType,
rView->getUnoView(),
getLeavingBitmap(ViewEntry(rView))->getXBitmap(),
getEnteringBitmap(ViewEntry(rView))->getXBitmap() );
if( rTransition.is() )
maTransitions.push_back( new TransitionViewPair( rTransition, rView ) );
else
return false;
return true;
}
virtual bool operator()( double t )
{
std::for_each(maTransitions.begin(),
maTransitions.end(),
boost::bind( &TransitionViewPair::update,
_1, t) );
return true;
}
bool Success()
{
return mbSuccess;
}
// ViewEventHandler
virtual void viewAdded( const UnoViewSharedPtr& rView )
{
OSL_TRACE("PluginSlideChange viewAdded");
SlideChangeBase::viewAdded( rView );
::std::vector< TransitionViewPair* >::const_iterator aCurrView (maTransitions.begin());
::std::vector< TransitionViewPair* >::const_iterator aEnd(maTransitions.end());
bool bKnown = false;
while( aCurrView != aEnd )
{
if( (*aCurrView)->mpView == rView ) {
bKnown = true;
break;
}
++aCurrView;
}
if( !bKnown ) {
OSL_TRACE("need to be added");
addTransition( rView );
}
}
virtual void viewRemoved( const UnoViewSharedPtr& rView )
{
OSL_TRACE("PluginSlideChange viewRemoved");
SlideChangeBase::viewRemoved( rView );
::std::vector< TransitionViewPair* >::iterator aCurrView (maTransitions.begin());
::std::vector< TransitionViewPair* >::const_iterator aEnd(maTransitions.end());
while( aCurrView != aEnd )
{
if( (*aCurrView)->mpView == rView ) {
OSL_TRACE( "view removed" );
delete (*aCurrView);
maTransitions.erase( aCurrView );
break;
}
++aCurrView;
}
}
virtual void viewChanged( const UnoViewSharedPtr& rView )
{
OSL_TRACE("PluginSlideChange viewChanged");
SlideChangeBase::viewChanged( rView );
::std::vector< TransitionViewPair* >::const_iterator aCurrView (maTransitions.begin());
::std::vector< TransitionViewPair* >::const_iterator aEnd(maTransitions.end());
while( aCurrView != aEnd )
{
if( (*aCurrView)->mpView == rView ) {
OSL_TRACE( "view changed" );
(*aCurrView)->mxTransition->viewChanged( rView->getUnoView(),
getLeavingBitmap(ViewEntry(rView))->getXBitmap(),
getEnteringBitmap(ViewEntry(rView))->getXBitmap() );
} else
OSL_TRACE( "view did not changed" );
++aCurrView;
}
}
virtual void viewsChanged()
{
OSL_TRACE("PluginSlideChange viewsChanged");
SlideChangeBase::viewsChanged();
::std::vector< TransitionViewPair* >::const_iterator aCurrView (maTransitions.begin());
::std::vector< TransitionViewPair* >::const_iterator aEnd(maTransitions.end());
while( aCurrView != aEnd )
{
OSL_TRACE( "view changed" );
(*aCurrView)->mxTransition->viewChanged( (*aCurrView)->mpView->getUnoView(),
getLeavingBitmap(ViewEntry((*aCurrView)->mpView))->getXBitmap(),
getEnteringBitmap(ViewEntry((*aCurrView)->mpView))->getXBitmap() );
++aCurrView;
}
}
private:
// One transition object per view
std::vector< TransitionViewPair* > maTransitions;
// bool
bool mbSuccess;
sal_Int16 mnTransitionType;
sal_Int16 mnTransitionSubType;
uno::Reference<presentation::XTransitionFactory> mxFactory;
};
class ClippedSlideChange : public SlideChangeBase
{
public:
/** Create a new SlideChanger, for the given leaving and
entering slide bitmaps, which applies the given clip
polygon.
*/
ClippedSlideChange(
const SlideSharedPtr& pEnteringSlide,
const ParametricPolyPolygonSharedPtr& rPolygon,
const TransitionInfo& rTransitionInfo,
const UnoViewContainer& rViewContainer,
ScreenUpdater& rScreenUpdater,
EventMultiplexer& rEventMultiplexer,
bool bDirectionForward,
const SoundPlayerSharedPtr& pSoundPlayer ) :
SlideChangeBase(
// leaving bitmap is empty, we're leveraging the fact that the
// old slide is still displayed in the background:
boost::optional<SlideSharedPtr>(),
pEnteringSlide,
pSoundPlayer,
rViewContainer,
rScreenUpdater,
rEventMultiplexer ),
maClippingFunctor( rPolygon,
rTransitionInfo,
bDirectionForward,
true )
{}
virtual void performIn(
const ::cppcanvas::CustomSpriteSharedPtr& rSprite,
const ViewEntry& rViewEntry,
const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
double t );
virtual void performOut(
const ::cppcanvas::CustomSpriteSharedPtr& rSprite,
const ViewEntry& rViewEntry,
const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
double t );
private:
ClippingFunctor maClippingFunctor;
};
void ClippedSlideChange::performIn(
const ::cppcanvas::CustomSpriteSharedPtr& rSprite,
const ViewEntry& rViewEntry,
const ::cppcanvas::CanvasSharedPtr& /*rDestinationCanvas*/,
double t )
{
// #i46602# Better work in device coordinate space here,
// otherwise, we too easily suffer from roundoffs. Apart from
// that, getEnteringSizePixel() _guarantees_ to cover the whole
// slide bitmap. There's a catch, though: this removes any effect
// of the view transformation (e.g. rotation) from the transition.
rSprite->setClipPixel(
maClippingFunctor( t,
getEnteringSlideSizePixel(rViewEntry.mpView) ) );
}
void ClippedSlideChange::performOut(
const ::cppcanvas::CustomSpriteSharedPtr& /*rSprite*/,
const ViewEntry& /*rViewEntry*/,
const ::cppcanvas::CanvasSharedPtr& /*rDestinationCanvas*/,
double /*t*/ )
{
// not needed here
}
class FadingSlideChange : public SlideChangeBase
{
public:
/** Create a new SlideChanger, for the given leaving and
entering slides, which applies a fade effect.
*/
FadingSlideChange(
boost::optional<SlideSharedPtr> const & leavingSlide,
const SlideSharedPtr& pEnteringSlide,
boost::optional<RGBColor> const& rFadeColor,
const SoundPlayerSharedPtr& pSoundPlayer,
const UnoViewContainer& rViewContainer,
ScreenUpdater& rScreenUpdater,
EventMultiplexer& rEventMultiplexer )
: SlideChangeBase( leavingSlide,
pEnteringSlide,
pSoundPlayer,
rViewContainer,
rScreenUpdater,
rEventMultiplexer ),
maFadeColor( rFadeColor ),
mbFirstTurn( true )
{}
virtual void performIn(
const ::cppcanvas::CustomSpriteSharedPtr& rSprite,
const ViewEntry& rViewEntry,
const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
double t );
virtual void performOut(
const ::cppcanvas::CustomSpriteSharedPtr& rSprite,
const ViewEntry& rViewEntry,
const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
double t );
private:
const boost::optional< RGBColor > maFadeColor;
bool mbFirstTurn;
};
void FadingSlideChange::performIn(
const ::cppcanvas::CustomSpriteSharedPtr& rSprite,
const ViewEntry& /*rViewEntry*/,
const ::cppcanvas::CanvasSharedPtr& /*rDestinationCanvas*/,
double t )
{
ENSURE_OR_THROW(
rSprite,
"FadingSlideChange::performIn(): Invalid sprite" );
if( maFadeColor )
// After half of the active time, fade in new slide
rSprite->setAlpha( t > 0.5 ? 2.0*(t-0.5) : 0.0 );
else
// Fade in new slide over full active time
rSprite->setAlpha( t );
}
void FadingSlideChange::performOut(
const ::cppcanvas::CustomSpriteSharedPtr& rSprite,
const ViewEntry& rViewEntry,
const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
double t )
{
ENSURE_OR_THROW(
rSprite,
"FadingSlideChange::performOut(): Invalid sprite" );
ENSURE_OR_THROW(
rDestinationCanvas,
"FadingSlideChange::performOut(): Invalid dest canvas" );
// only needed for color fades
if( maFadeColor )
{
if( mbFirstTurn )
{
mbFirstTurn = false;
// clear page to given fade color. 'Leaving' slide is
// painted atop of that, but slowly fading out.
fillPage( rDestinationCanvas,
getEnteringSlideSizePixel( rViewEntry.mpView ),
*maFadeColor );
}
// Until half of the active time, fade out old
// slide. After half of the active time, old slide
// will be invisible.
rSprite->setAlpha( t > 0.5 ? 0.0 : 2.0*(0.5-t) );
}
}
class CutSlideChange : public SlideChangeBase
{
public:
/** Create a new SlideChanger, for the given leaving and
entering slides, which applies a cut effect.
*/
CutSlideChange(
boost::optional<SlideSharedPtr> const & leavingSlide,
const SlideSharedPtr& pEnteringSlide,
const RGBColor& rFadeColor,
const SoundPlayerSharedPtr& pSoundPlayer,
const UnoViewContainer& rViewContainer,
ScreenUpdater& rScreenUpdater,
EventMultiplexer& rEventMultiplexer )
: SlideChangeBase( leavingSlide,
pEnteringSlide,
pSoundPlayer,
rViewContainer,
rScreenUpdater,
rEventMultiplexer ),
maFadeColor( rFadeColor ),
mbFirstTurn( true )
{}
virtual void performIn(
const ::cppcanvas::CustomSpriteSharedPtr& rSprite,
const ViewEntry& rViewEntry,
const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
double t );
virtual void performOut(
const ::cppcanvas::CustomSpriteSharedPtr& rSprite,
const ViewEntry& rViewEntry,
const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
double t );
private:
RGBColor maFadeColor;
bool mbFirstTurn;
};
void CutSlideChange::performIn(
const ::cppcanvas::CustomSpriteSharedPtr& rSprite,
const ViewEntry& /*rViewEntry*/,
const ::cppcanvas::CanvasSharedPtr& /*rDestinationCanvas*/,
double t )
{
ENSURE_OR_THROW(
rSprite,
"CutSlideChange::performIn(): Invalid sprite" );
// After 2/3rd of the active time, display new slide
rSprite->setAlpha( t > 2/3.0 ? 1.0 : 0.0 );
}
void CutSlideChange::performOut(
const ::cppcanvas::CustomSpriteSharedPtr& rSprite,
const ViewEntry& rViewEntry,
const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
double t )
{
ENSURE_OR_THROW(
rSprite,
"CutSlideChange::performOut(): Invalid sprite" );
ENSURE_OR_THROW(
rDestinationCanvas,
"FadingSlideChange::performOut(): Invalid dest canvas" );
if( mbFirstTurn )
{
mbFirstTurn = false;
// clear page to given fade color. 'Leaving' slide is
// painted atop of that
fillPage( rDestinationCanvas,
getEnteringSlideSizePixel( rViewEntry.mpView ),
maFadeColor );
}
// Until 1/3rd of the active time, display old slide.
rSprite->setAlpha( t > 1/3.0 ? 0.0 : 1.0 );
}
class MovingSlideChange : public SlideChangeBase
{
/// Direction vector for leaving slide,
const ::basegfx::B2DVector maLeavingDirection;
/// Direction vector for entering slide,
const ::basegfx::B2DVector maEnteringDirection;
bool mbFirstPerformCall;
public:
/** Create a new SlideChanger, for the given entering slide
bitmaps, which performes a moving slide change effect
@param rLeavingDirection
Direction vector. The move is performed along this
direction vector, starting at a position where the leaving
slide is fully visible, and ending at a position where the
leaving slide is just not visible. The vector must have
unit length.
@param rEnteringDirection
Direction vector. The move is performed along this
direction vector, starting at a position where the
entering slide is just not visible, and ending at the
final slide position. The vector must have unit length.
*/
MovingSlideChange(
const boost::optional<SlideSharedPtr>& leavingSlide,
const SlideSharedPtr& pEnteringSlide,
const SoundPlayerSharedPtr& pSoundPlayer,
const UnoViewContainer& rViewContainer,
ScreenUpdater& rScreenUpdater,
EventMultiplexer& rEventMultiplexer,
const ::basegfx::B2DVector& rLeavingDirection,
const ::basegfx::B2DVector& rEnteringDirection )
: SlideChangeBase(
leavingSlide, pEnteringSlide, pSoundPlayer,
rViewContainer, rScreenUpdater, rEventMultiplexer,
// Optimization: when leaving bitmap is given,
// but it does not move, don't create sprites for it,
// we simply paint it once at startup:
!rLeavingDirection.equalZero() /* bCreateLeavingSprites */,
!rEnteringDirection.equalZero() /* bCreateEnteringSprites */ ),
// TODO(F1): calc correct length of direction
// vector. Directions not strictly horizontal or vertical
// must travel a longer distance.
maLeavingDirection( rLeavingDirection ),
// TODO(F1): calc correct length of direction
// vector. Directions not strictly horizontal or vertical
// must travel a longer distance.
maEnteringDirection( rEnteringDirection ),
mbFirstPerformCall( true )
{}
virtual void performIn(
const ::cppcanvas::CustomSpriteSharedPtr& rSprite,
const ViewEntry& rViewEntry,
const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
double t );
virtual void performOut(
const ::cppcanvas::CustomSpriteSharedPtr& rSprite,
const ViewEntry& rViewEntry,
const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
double t );
};
void MovingSlideChange::performIn(
const ::cppcanvas::CustomSpriteSharedPtr& rSprite,
const ViewEntry& rViewEntry,
const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
double t )
{
// intro sprite moves:
ENSURE_OR_THROW(
rSprite,
"MovingSlideChange::performIn(): Invalid sprite" );
ENSURE_OR_THROW(
rDestinationCanvas,
"MovingSlideChange::performIn(): Invalid dest canvas" );
if (mbFirstPerformCall && maLeavingDirection.equalZero())
{
mbFirstPerformCall = false;
renderBitmap( getLeavingBitmap(rViewEntry), rDestinationCanvas );
}
// TODO(F1): This does not account for non-translational
// transformations! If the canvas is rotated, we still
// move the sprite unrotated (which might or might not
// produce the intended effect).
const basegfx::B2DHomMatrix aViewTransform(
rDestinationCanvas->getTransformation() );
const basegfx::B2DPoint aPageOrigin(
aViewTransform * basegfx::B2DPoint() );
// move sprite
rSprite->movePixel(
aPageOrigin +
((t - 1.0) *
::basegfx::B2DSize( getEnteringSlideSizePixel(rViewEntry.mpView) ) *
maEnteringDirection) );
}
void MovingSlideChange::performOut(
const ::cppcanvas::CustomSpriteSharedPtr& rSprite,
const ViewEntry& rViewEntry,
const ::cppcanvas::CanvasSharedPtr& rDestinationCanvas,
double t )
{
// outro sprite moves:
ENSURE_OR_THROW(
rSprite,
"MovingSlideChange::performOut(): Invalid sprite" );
ENSURE_OR_THROW(
rDestinationCanvas,
"MovingSlideChange::performOut(): Invalid dest canvas" );
if (mbFirstPerformCall && maEnteringDirection.equalZero())
{
mbFirstPerformCall = false;
renderBitmap( getEnteringBitmap(rViewEntry), rDestinationCanvas );
}
// TODO(F1): This does not account for non-translational
// transformations! If the canvas is rotated, we still
// move the sprite unrotated (which might or might not
// produce the intended effect).
const basegfx::B2DHomMatrix aViewTransform(
rDestinationCanvas->getTransformation() );
const basegfx::B2DPoint aPageOrigin(
aViewTransform * basegfx::B2DPoint() );
// move sprite
rSprite->movePixel(
aPageOrigin + (t *
::basegfx::B2DSize( getEnteringSlideSizePixel(rViewEntry.mpView) ) *
maLeavingDirection) );
}
NumberAnimationSharedPtr createPushWipeTransition(
boost::optional<SlideSharedPtr> const & leavingSlide_,
const SlideSharedPtr& pEnteringSlide,
const UnoViewContainer& rViewContainer,
ScreenUpdater& rScreenUpdater,
EventMultiplexer& rEventMultiplexer,
sal_Int16 /*nTransitionType*/,
sal_Int16 nTransitionSubType,
bool /*bTransitionDirection*/,
const SoundPlayerSharedPtr& pSoundPlayer )
{
boost::optional<SlideSharedPtr> leavingSlide; // no bitmap
if (leavingSlide_ && (*leavingSlide_).get() != 0)
{
// opt: only page, if we've an
// actual slide to move out here. We
// _don't_ need a fake black background
// bitmap, neither for push nor for comb
// wipes.
leavingSlide = leavingSlide_;
}
// setup direction vector
bool bComb( false );
::basegfx::B2DVector aDirection;
switch( nTransitionSubType )
{
default:
OSL_FAIL(
"createPushWipeTransition(): Unexpected transition "
"subtype for animations::TransitionType::PUSHWIPE "
"transitions" );
return NumberAnimationSharedPtr();
case animations::TransitionSubType::FROMTOP:
aDirection = ::basegfx::B2DVector( 0.0, 1.0 );
break;
case animations::TransitionSubType::FROMBOTTOM:
aDirection = ::basegfx::B2DVector( 0.0, -1.0 );
break;
case animations::TransitionSubType::FROMLEFT:
aDirection = ::basegfx::B2DVector( 1.0, 0.0 );
break;
case animations::TransitionSubType::FROMRIGHT:
aDirection = ::basegfx::B2DVector( -1.0, 0.0 );
break;
case animations::TransitionSubType::FROMBOTTOMRIGHT:
aDirection = ::basegfx::B2DVector( -1.0, -1.0 );
break;
case animations::TransitionSubType::FROMBOTTOMLEFT:
aDirection = ::basegfx::B2DVector( 1.0, -1.0 );
break;
case animations::TransitionSubType::FROMTOPRIGHT:
aDirection = ::basegfx::B2DVector( -1.0, 1.0 );
break;
case animations::TransitionSubType::FROMTOPLEFT:
aDirection = ::basegfx::B2DVector( 1.0, 1.0 );
break;
case animations::TransitionSubType::COMBHORIZONTAL:
aDirection = ::basegfx::B2DVector( 1.0, 0.0 );
bComb = true;
break;
case animations::TransitionSubType::COMBVERTICAL:
aDirection = ::basegfx::B2DVector( 0.0, 1.0 );
bComb = true;
break;
}
if( bComb )
{
return NumberAnimationSharedPtr(
new CombTransition( leavingSlide,
pEnteringSlide,
pSoundPlayer,
rViewContainer,
rScreenUpdater,
rEventMultiplexer,
aDirection,
24 /* comb with 12 stripes */ ));
}
else
{
return NumberAnimationSharedPtr(
new MovingSlideChange( leavingSlide,
pEnteringSlide,
pSoundPlayer,
rViewContainer,
rScreenUpdater,
rEventMultiplexer,
aDirection,
aDirection ));
}
}
NumberAnimationSharedPtr createSlideWipeTransition(
boost::optional<SlideSharedPtr> const & leavingSlide,
const SlideSharedPtr& pEnteringSlide,
const UnoViewContainer& rViewContainer,
ScreenUpdater& rScreenUpdater,
EventMultiplexer& rEventMultiplexer,
sal_Int16 /*nTransitionType*/,
sal_Int16 nTransitionSubType,
bool bTransitionDirection,
const SoundPlayerSharedPtr& pSoundPlayer )
{
// setup 'in' direction vector
::basegfx::B2DVector aInDirection;
switch( nTransitionSubType )
{
default:
OSL_FAIL(
"createSlideWipeTransition(): Unexpected transition "
"subtype for animations::TransitionType::SLIDEWIPE "
"transitions" );
return NumberAnimationSharedPtr();
case animations::TransitionSubType::FROMTOP:
aInDirection = ::basegfx::B2DVector( 0.0, 1.0 );
break;
case animations::TransitionSubType::FROMRIGHT:
aInDirection = ::basegfx::B2DVector( -1.0, 0.0 );
break;
case animations::TransitionSubType::FROMLEFT:
aInDirection = ::basegfx::B2DVector( 1.0, 0.0 );
break;
case animations::TransitionSubType::FROMBOTTOM:
aInDirection = ::basegfx::B2DVector( 0.0, -1.0 );
break;
case animations::TransitionSubType::FROMBOTTOMRIGHT:
aInDirection = ::basegfx::B2DVector( -1.0, -1.0 );
break;
case animations::TransitionSubType::FROMBOTTOMLEFT:
aInDirection = ::basegfx::B2DVector( 1.0, -1.0 );
break;
case animations::TransitionSubType::FROMTOPRIGHT:
aInDirection = ::basegfx::B2DVector( -1.0, 1.0 );
break;
case animations::TransitionSubType::FROMTOPLEFT:
aInDirection = ::basegfx::B2DVector( 1.0, 1.0 );
break;
}
if( bTransitionDirection )
{
// normal, 'forward' slide wipe effect. Since the old
// content is still on screen (and does not move), we omit
// the 'leaving' slide.
// =======================================================
return NumberAnimationSharedPtr(
new MovingSlideChange(
boost::optional<SlideSharedPtr>() /* no slide */,
pEnteringSlide,
pSoundPlayer,
rViewContainer,
rScreenUpdater,
rEventMultiplexer,
basegfx::B2DVector(),
aInDirection ));
}
else
{
// 'reversed' slide wipe effect. Reverse for slide wipes
// means, that the new slide is in the back, statically,
// and the old one is moving off in the foreground.
// =======================================================
return NumberAnimationSharedPtr(
new MovingSlideChange( leavingSlide,
pEnteringSlide,
pSoundPlayer,
rViewContainer,
rScreenUpdater,
rEventMultiplexer,
aInDirection,
basegfx::B2DVector() ));
}
}
NumberAnimationSharedPtr createPluginTransition(
sal_Int16 nTransitionType,
sal_Int16 nTransitionSubType,
boost::optional<SlideSharedPtr> const& pLeavingSlide,
const SlideSharedPtr& pEnteringSlide,
const UnoViewContainer& rViewContainer,
ScreenUpdater& rScreenUpdater,
const uno::Reference<
presentation::XTransitionFactory>& xFactory,
const SoundPlayerSharedPtr& pSoundPlayer,
EventMultiplexer& rEventMultiplexer)
{
PluginSlideChange* pTransition =
new PluginSlideChange(
nTransitionType,
nTransitionSubType,
pLeavingSlide,
pEnteringSlide,
rViewContainer,
rScreenUpdater,
xFactory,
pSoundPlayer,
rEventMultiplexer );
if( pTransition->Success() )
return NumberAnimationSharedPtr( pTransition );
else {
delete pTransition;
return NumberAnimationSharedPtr();
}
}
} // anon namespace
NumberAnimationSharedPtr TransitionFactory::createSlideTransition(
const SlideSharedPtr& pLeavingSlide,
const SlideSharedPtr& pEnteringSlide,
const UnoViewContainer& rViewContainer,
ScreenUpdater& rScreenUpdater,
EventMultiplexer& rEventMultiplexer,
const uno::Reference<presentation::XTransitionFactory>& xOptionalFactory,
sal_Int16 nTransitionType,
sal_Int16 nTransitionSubType,
bool bTransitionDirection,
const RGBColor& rTransitionFadeColor,
const SoundPlayerSharedPtr& pSoundPlayer )
{
// xxx todo: change to TransitionType::NONE, TransitionSubType::NONE:
if (nTransitionType == 0 && nTransitionSubType == 0) {
// just play sound, no slide transition:
if (pSoundPlayer) {
pSoundPlayer->startPlayback();
// xxx todo: for now, presentation.cxx takes care about the slide
// #i50492# transition sound object, so just release it here
}
return NumberAnimationSharedPtr();
}
ENSURE_OR_THROW(
pEnteringSlide,
"TransitionFactory::createSlideTransition(): Invalid entering slide" );
if( xOptionalFactory.is() &&
xOptionalFactory->hasTransition(nTransitionType, nTransitionSubType) )
{
// #i82460# - optional plugin factory claims this transition. delegate.
NumberAnimationSharedPtr pTransition(
createPluginTransition(
nTransitionType,
nTransitionSubType,
comphelper::make_optional(pLeavingSlide),
pEnteringSlide,
rViewContainer,
rScreenUpdater,
xOptionalFactory,
pSoundPlayer,
rEventMultiplexer ));
if( pTransition.get() )
return pTransition;
}
const TransitionInfo* pTransitionInfo(
getTransitionInfo( nTransitionType, nTransitionSubType ) );
if( pTransitionInfo != NULL )
{
switch( pTransitionInfo->meTransitionClass )
{
default:
case TransitionInfo::TRANSITION_INVALID:
OSL_TRACE(
"TransitionFactory::createSlideTransition(): "
"Invalid type/subtype (%d/%d) combination encountered.",
nTransitionType,
nTransitionSubType );
return NumberAnimationSharedPtr();
case TransitionInfo::TRANSITION_CLIP_POLYPOLYGON:
{
// generate parametric poly-polygon
ParametricPolyPolygonSharedPtr pPoly(
ParametricPolyPolygonFactory::createClipPolyPolygon(
nTransitionType, nTransitionSubType ) );
// create a clip transition from that
return NumberAnimationSharedPtr(
new ClippedSlideChange( pEnteringSlide,
pPoly,
*pTransitionInfo,
rViewContainer,
rScreenUpdater,
rEventMultiplexer,
bTransitionDirection,
pSoundPlayer ));
}
case TransitionInfo::TRANSITION_SPECIAL:
{
switch( nTransitionType )
{
default:
OSL_FAIL(
"TransitionFactory::createSlideTransition(): "
"Unexpected transition type for "
"TRANSITION_SPECIAL transitions" );
return NumberAnimationSharedPtr();
case animations::TransitionType::RANDOM:
{
// select randomly one of the effects from the
// TransitionFactoryTable
const TransitionInfo* pRandomTransitionInfo(
getRandomTransitionInfo() );
ENSURE_OR_THROW(
pRandomTransitionInfo != NULL,
"TransitionFactory::createSlideTransition(): "
"Got invalid random transition info" );
ENSURE_OR_THROW(
pRandomTransitionInfo->mnTransitionType !=
animations::TransitionType::RANDOM,
"TransitionFactory::createSlideTransition(): "
"Got random again for random input!" );
// and recurse
return createSlideTransition(
pLeavingSlide,
pEnteringSlide,
rViewContainer,
rScreenUpdater,
rEventMultiplexer,
xOptionalFactory,
pRandomTransitionInfo->mnTransitionType,
pRandomTransitionInfo->mnTransitionSubType,
bTransitionDirection,
rTransitionFadeColor,
pSoundPlayer );
}
case animations::TransitionType::PUSHWIPE:
{
return createPushWipeTransition(
comphelper::make_optional(pLeavingSlide),
pEnteringSlide,
rViewContainer,
rScreenUpdater,
rEventMultiplexer,
nTransitionType,
nTransitionSubType,
bTransitionDirection,
pSoundPlayer );
}
case animations::TransitionType::SLIDEWIPE:
{
return createSlideWipeTransition(
comphelper::make_optional(pLeavingSlide),
pEnteringSlide,
rViewContainer,
rScreenUpdater,
rEventMultiplexer,
nTransitionType,
nTransitionSubType,
bTransitionDirection,
pSoundPlayer );
}
case animations::TransitionType::BARWIPE:
case animations::TransitionType::FADE:
{
// black page:
boost::optional<SlideSharedPtr> leavingSlide;
switch( nTransitionSubType )
{
case animations::TransitionSubType::CROSSFADE:
// crossfade needs no further setup,
// just blend new slide over existing
// background.
break;
// TODO(F1): Implement toColor/fromColor fades
case animations::TransitionSubType::FADETOCOLOR:
// FALLTHROUGH intended
case animations::TransitionSubType::FADEFROMCOLOR:
// FALLTHROUGH intended
case animations::TransitionSubType::FADEOVERCOLOR:
if (pLeavingSlide) {
// only generate, if fade
// effect really needs it.
leavingSlide.reset( pLeavingSlide );
}
break;
default:
ENSURE_OR_THROW( false,
"SlideTransitionFactory::createSlideTransition(): Unknown FADE subtype" );
}
if( nTransitionType == animations::TransitionType::FADE )
return NumberAnimationSharedPtr(
new FadingSlideChange(
leavingSlide,
pEnteringSlide,
comphelper::make_optional(
rTransitionFadeColor),
pSoundPlayer,
rViewContainer,
rScreenUpdater,
rEventMultiplexer ));
else
return NumberAnimationSharedPtr(
new CutSlideChange(
leavingSlide,
pEnteringSlide,
rTransitionFadeColor,
pSoundPlayer,
rViewContainer,
rScreenUpdater,
rEventMultiplexer ));
}
}
}
break;
}
}
// No animation generated, maybe no table entry for given
// transition?
OSL_TRACE(
"TransitionFactory::createSlideTransition(): "
"Unknown type/subtype (%d/%d) combination encountered",
nTransitionType,
nTransitionSubType );
OSL_FAIL(
"TransitionFactory::createSlideTransition(): "
"Unknown type/subtype combination encountered" );
return NumberAnimationSharedPtr();
}
} // namespace internal
} // namespace presentation
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|