File indexing completed on 2025-01-05 03:57:25

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2017-05-24
0007  * Description : images transition manager.
0008  *
0009  * SPDX-FileCopyrightText: 2017-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "transitionmngr_p.h"
0016 
0017 namespace Digikam
0018 {
0019 
0020 int TransitionMngr::Private::transitionChessboard(bool aInit)
0021 {
0022     if (aInit)
0023     {
0024         eff_w    = eff_outSize.width();
0025         eff_h    = eff_outSize.height();
0026         eff_dx   = 8;                                // width of one tile
0027         eff_dy   = 8;                                // height of one tile
0028         eff_j    = (eff_w + eff_dx - 1) / eff_dx;    // number of tiles
0029         eff_x    = eff_j * eff_dx;                   // shrinking x-offset from screen border
0030         eff_ix   = 0;                                // growing x-offset from screen border
0031         eff_iy   = 0;                                // 0 or eff_dy for growing tiling effect
0032         eff_y    = (eff_j & 1) ? 0 : eff_dy;         // 0 or eff_dy for shrinking tiling effect
0033         eff_wait = 800 / eff_j;                      // timeout between effects
0034     }
0035 
0036     if (eff_ix >= eff_w)
0037     {
0038         eff_curFrame = eff_outImage;
0039         return -1;
0040     }
0041 
0042     eff_ix += eff_dx;
0043     eff_x  -= eff_dx;
0044     eff_iy  = eff_iy ? 0 : eff_dy;
0045     eff_y   = eff_y  ? 0 : eff_dy;
0046 
0047     QPainter bufferPainter(&eff_curFrame);
0048     QBrush brush = QBrush(eff_outImage);
0049 
0050     for (int y = 0 ; y < eff_w ; y += (eff_dy << 1))
0051     {
0052         bufferPainter.fillRect(eff_ix, y + eff_iy, eff_dx, eff_dy, brush);
0053         bufferPainter.fillRect(eff_x, y + eff_y, eff_dx, eff_dy, brush);
0054     }
0055 
0056     return eff_wait;
0057 }
0058 
0059 int TransitionMngr::Private::transitionGrowing(bool aInit)
0060 {
0061     if (aInit)
0062     {
0063         eff_w  = eff_outSize.width();
0064         eff_h  = eff_outSize.height();
0065         eff_x  = eff_w >> 1;
0066         eff_y  = eff_h >> 1;
0067         eff_i  = 0;
0068         eff_fx = eff_x / 100.0;
0069         eff_fy = eff_y / 100.0;
0070     }
0071 
0072     eff_x = (eff_w >> 1) - (int)(eff_i * eff_fx);
0073     eff_y = (eff_h >> 1) - (int)(eff_i * eff_fy);
0074     eff_i++;
0075 
0076     if ((eff_x < 0) || (eff_y < 0))
0077     {
0078         eff_curFrame = eff_outImage;
0079         return -1;
0080     }
0081 
0082     eff_px  = eff_x;
0083     eff_py  = eff_y;
0084     eff_psx = eff_w - (eff_x << 1);
0085     eff_psy = eff_h - (eff_y << 1);
0086 
0087     QPainter bufferPainter(&eff_curFrame);
0088     bufferPainter.fillRect(eff_px, eff_py, eff_psx, eff_psy, QBrush(eff_outImage));
0089     bufferPainter.end();
0090 
0091     return 20;
0092 }
0093 
0094 int TransitionMngr::Private::transitionSpiralIn(bool aInit)
0095 {
0096     if (aInit)
0097     {
0098         eff_w  = eff_outSize.width();
0099         eff_h  = eff_outSize.height();
0100         eff_ix = eff_w / 8;
0101         eff_iy = eff_h / 8;
0102         eff_x0 = 0;
0103         eff_x1 = eff_w - eff_ix;
0104         eff_y0 = eff_iy;
0105         eff_y1 = eff_h - eff_iy;
0106         eff_dx = eff_ix;
0107         eff_dy = 0;
0108         eff_i  = 0;
0109         eff_j  = 16 * 16;
0110         eff_x  = 0;
0111         eff_y  = 0;
0112     }
0113 
0114     if ((eff_i == 0) && (eff_x0 >= eff_x1))
0115     {
0116         eff_curFrame = eff_outImage;
0117         return -1;
0118     }
0119 
0120     if      ((eff_i == 0) && (eff_x >= eff_x1))      // switch to: down on right side
0121     {
0122         eff_i   = 1;
0123         eff_dx  = 0;
0124         eff_dy  = eff_iy;
0125         eff_x1 -= eff_ix;
0126     }
0127     else if ((eff_i == 1) && (eff_y >= eff_y1)) // switch to: right to left on bottom side
0128     {
0129         eff_i   = 2;
0130         eff_dx  = -eff_ix;
0131         eff_dy  = 0;
0132         eff_y1 -= eff_iy;
0133     }
0134     else if ((eff_i == 2) && (eff_x <= eff_x0)) // switch to: up on left side
0135     {
0136         eff_i   = 3;
0137         eff_dx  = 0;
0138         eff_dy  = -eff_iy;
0139         eff_x0 += eff_ix;
0140     }
0141     else if ((eff_i == 3) && (eff_y <= eff_y0)) // switch to: left to right on top side
0142     {
0143         eff_i   = 0;
0144         eff_dx  = eff_ix;
0145         eff_dy  = 0;
0146         eff_y0 += eff_iy;
0147     }
0148 
0149     eff_px  = eff_x;
0150     eff_py  = eff_y;
0151     eff_psx = eff_ix;
0152     eff_psy = eff_iy;
0153 
0154     QPainter bufferPainter(&eff_curFrame);
0155     bufferPainter.fillRect(eff_px, eff_py, eff_psx, eff_psy, QBrush(eff_outImage));
0156     bufferPainter.end();
0157 
0158     eff_x += eff_dx;
0159     eff_y += eff_dy;
0160     eff_j--;
0161 
0162     return 8;
0163 }
0164 
0165 } // namespace Digikam