2023-04-18 14:14:46 +08:00
|
|
|
#ifndef PLAYWIN_H
|
|
|
|
#define PLAYWIN_H
|
2023-10-23 14:58:29 +08:00
|
|
|
#include "gutil/qjson.h"
|
2023-04-18 14:14:46 +08:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QMap>
|
|
|
|
|
2024-02-21 18:08:50 +08:00
|
|
|
enum Effect {
|
|
|
|
EXPAND_HOR, EXPAND_VER, EXPAND_LEFT, EXPAND_TOP, EXPAND_RIGHT, EXPAND_BOTTOM,
|
|
|
|
ZOOM, ZOOM_TL, ZOOM_TR, ZOOM_BR, ZOOM_BL,
|
|
|
|
ROTATE, ROTATE_R,
|
|
|
|
FADE,
|
|
|
|
MOVE_LEFT, MOVE_TOP, MOVE_RIGHT, MOVE_BOTTOM,
|
|
|
|
End
|
|
|
|
};
|
|
|
|
|
|
|
|
class Source {
|
2023-10-23 14:58:29 +08:00
|
|
|
public:
|
2024-02-21 18:08:50 +08:00
|
|
|
QWidget *view = 0;
|
|
|
|
int64_t startMilli = 0, endMilli = LLONG_MAX;
|
|
|
|
int startTime = 0, entryDur = 0, exitStart = INT_MAX, exitDur = 0, endTime = 0, ff = 0;
|
|
|
|
Effect entryEff, exitEff;
|
2023-10-23 14:58:29 +08:00
|
|
|
QString type;
|
2024-02-21 18:08:50 +08:00
|
|
|
bool isEntryRand = 0, isExitRand = 0;
|
2023-10-23 14:58:29 +08:00
|
|
|
|
2024-02-21 18:08:50 +08:00
|
|
|
void show() {
|
|
|
|
if(view->isVisible()) return;
|
|
|
|
view->setVisible(true);
|
|
|
|
ff = 0;
|
|
|
|
if(isEntryRand) entryEff = (Effect) (rand() % Effect::End);
|
|
|
|
if(isExitRand) exitEff = (Effect) (rand() % Effect::End);
|
|
|
|
resetEff();
|
|
|
|
doEff();
|
|
|
|
}
|
|
|
|
void hide() {
|
|
|
|
if(! view->isVisible()) return;
|
|
|
|
view->setVisible(false);
|
|
|
|
}
|
|
|
|
void doEff() {
|
|
|
|
// auto w = view->width();
|
|
|
|
// auto h = view->height();
|
|
|
|
// if(ff < entryDur) {
|
|
|
|
// if(entryEff == Effect::EXPAND_HOR) view.setScaleX(ff / (float) entryDur);
|
|
|
|
// else if(entryEff == Effect::EXPAND_VER) view.setScaleY(ff / (float) entryDur);
|
|
|
|
// else if(entryEff == Effect::EXPAND_LEFT) {
|
|
|
|
// view.setScaleX(ff / (float) entryDur);
|
|
|
|
// view.setTranslationX((1 - view.getScaleX()) * w / 2);
|
|
|
|
// } else if(entryEff == Effect::EXPAND_TOP) {
|
|
|
|
// view.setScaleY(ff / (float) entryDur);
|
|
|
|
// view.setTranslationY((1 - view.getScaleY()) * h / 2);
|
|
|
|
// } else if(entryEff == Effect::EXPAND_RIGHT) {
|
|
|
|
// view.setScaleX(ff / (float) entryDur);
|
|
|
|
// view.setTranslationX((view.getScaleX() - 1) * w / 2);
|
|
|
|
// } else if(entryEff == Effect::EXPAND_BOTTOM) {
|
|
|
|
// view.setScaleY(ff / (float) entryDur);
|
|
|
|
// view.setTranslationY((view.getScaleY() - 1) * h / 2);
|
|
|
|
// }
|
|
|
|
// else if(entryEff == Effect::MOVE_LEFT) view.setTranslationX(w - ff*w/(float) entryDur);
|
|
|
|
// else if(entryEff == Effect::MOVE_TOP) view.setTranslationY(h - ff*h/(float) entryDur);
|
|
|
|
// else if(entryEff == Effect::MOVE_RIGHT) view.setTranslationX(ff*w/(float) entryDur - w);
|
|
|
|
// else if(entryEff == Effect::MOVE_BOTTOM) view.setTranslationY(ff*h/(float) entryDur - h);
|
|
|
|
// else if(entryEff == Effect::FADE) view.setAlpha(ff / (float) entryDur);
|
|
|
|
// else if(entryEff == Effect::ZOOM) {
|
|
|
|
// view.setScaleX(ff / (float) entryDur);
|
|
|
|
// view.setScaleY(view.getScaleX());
|
|
|
|
// } else if(entryEff == Effect::ZOOM_TL) {
|
|
|
|
// var rate = ff / (float) entryDur;
|
|
|
|
// view.setTranslationX((rate - 1) * w / 2);
|
|
|
|
// view.setTranslationY((rate - 1) * h / 2);
|
|
|
|
// view.setScaleX(rate);
|
|
|
|
// view.setScaleY(rate);
|
|
|
|
// } else if(entryEff == Effect::ZOOM_BR) {
|
|
|
|
// var rate = ff / (float) entryDur;
|
|
|
|
// view.setTranslationX((1 - rate) * w / 2);
|
|
|
|
// view.setTranslationY((1 - rate) * h / 2);
|
|
|
|
// view.setScaleX(rate);
|
|
|
|
// view.setScaleY(rate);
|
|
|
|
// } else if(entryEff == Effect::ZOOM_TR) {
|
|
|
|
// var rate = ff / (float) entryDur;
|
|
|
|
// view.setTranslationX((1 - rate) * w / 2);
|
|
|
|
// view.setTranslationY((rate - 1) * h / 2);
|
|
|
|
// view.setScaleX(rate);
|
|
|
|
// view.setScaleY(rate);
|
|
|
|
// } else if(entryEff == Effect::ZOOM_BL) {
|
|
|
|
// var rate = ff / (float) entryDur;
|
|
|
|
// view.setTranslationX((rate - 1) * w / 2);
|
|
|
|
// view.setTranslationY((1 - rate) * h / 2);
|
|
|
|
// view.setScaleX(rate);
|
|
|
|
// view.setScaleY(rate);
|
|
|
|
// } else if(entryEff == Effect::ROTATE) {
|
|
|
|
// view.setScaleX(ff / (float) entryDur);
|
|
|
|
// view.setScaleY(view.getScaleX());
|
|
|
|
// view.setRotation(view.getScaleX() * 360);
|
|
|
|
// } else if(entryEff == Effect::ROTATE_R) {
|
|
|
|
// view.setScaleX(ff / (float) entryDur);
|
|
|
|
// view.setScaleY(view.getScaleX());
|
|
|
|
// view.setRotation(- view.getScaleX() * 360);
|
|
|
|
// }
|
|
|
|
// } else if(ff>=exitStart) {
|
|
|
|
// var fff = ff - exitStart;
|
|
|
|
// if(fff > exitDur) fff = exitDur;
|
|
|
|
// if(exitEff == Effect::EXPAND_HOR) view.setScaleX(1 - fff / (float) exitDur);
|
|
|
|
// else if(exitEff == Effect::EXPAND_VER) view.setScaleY(1 - fff / (float) exitDur);
|
|
|
|
// else if(exitEff == Effect::EXPAND_LEFT) {
|
|
|
|
// var rate = fff / (float) exitDur;
|
|
|
|
// view.setScaleX(1 - rate);
|
|
|
|
// view.setTranslationX(rate * w / 2);
|
|
|
|
// } else if(exitEff == Effect::EXPAND_TOP) {
|
|
|
|
// var rate = fff / (float) exitDur;
|
|
|
|
// view.setScaleY(1 - rate);
|
|
|
|
// view.setTranslationY(rate * h / 2);
|
|
|
|
// } else if(exitEff == Effect::EXPAND_RIGHT) {
|
|
|
|
// var rate = fff / (float) exitDur;
|
|
|
|
// view.setScaleX(1 - rate);
|
|
|
|
// view.setTranslationX(- rate * w / 2);
|
|
|
|
// } else if(exitEff == Effect::EXPAND_BOTTOM) {
|
|
|
|
// var rate = fff / (float) exitDur;
|
|
|
|
// view.setScaleY(1 - rate);
|
|
|
|
// view.setTranslationY(- rate * h / 2);
|
|
|
|
// }
|
|
|
|
// else if(exitEff == Effect::MOVE_LEFT) view.setTranslationX(- fff*w / (float) exitDur);
|
|
|
|
// else if(exitEff == Effect::MOVE_RIGHT) view.setTranslationX(fff*w / (float) exitDur);
|
|
|
|
// else if(exitEff == Effect::MOVE_TOP) view.setTranslationY(- fff*h / (float) exitDur);
|
|
|
|
// else if(exitEff == Effect::MOVE_BOTTOM) view.setTranslationY(fff*h / (float) exitDur);
|
|
|
|
// else if(exitEff == Effect::FADE) view.setAlpha(1 - fff / (float) exitDur);
|
|
|
|
// else if(exitEff == Effect::ZOOM) {
|
|
|
|
// view.setScaleX(1 - fff / (float) exitDur);
|
|
|
|
// view.setScaleY(view.getScaleX());
|
|
|
|
// } else if(exitEff == Effect::ZOOM_TL) {
|
|
|
|
// var rate = fff / (float) exitDur;
|
|
|
|
// view.setTranslationX(- rate * w / 2);
|
|
|
|
// view.setTranslationY(- rate * h / 2);
|
|
|
|
// view.setScaleX(1 - rate);
|
|
|
|
// view.setScaleY(1 - rate);
|
|
|
|
// } else if(exitEff == Effect::ZOOM_BR) {
|
|
|
|
// var rate = fff / (float) exitDur;
|
|
|
|
// view.setTranslationX(rate * w / 2);
|
|
|
|
// view.setTranslationY(rate * h / 2);
|
|
|
|
// view.setScaleX(1 - rate);
|
|
|
|
// view.setScaleY(1 - rate);
|
|
|
|
// } else if(exitEff == Effect::ZOOM_TR) {
|
|
|
|
// var rate = fff / (float) exitDur;
|
|
|
|
// view.setTranslationX(rate * w / 2);
|
|
|
|
// view.setTranslationY(- rate * h / 2);
|
|
|
|
// view.setScaleX(1 - rate);
|
|
|
|
// view.setScaleY(1 - rate);
|
|
|
|
// } else if(exitEff == Effect::ZOOM_BL) {
|
|
|
|
// var rate = fff / (float) exitDur;
|
|
|
|
// view.setTranslationX(- rate * w / 2);
|
|
|
|
// view.setTranslationY(rate * h / 2);
|
|
|
|
// view.setScaleX(1 - rate);
|
|
|
|
// view.setScaleY(1 - rate);
|
|
|
|
// } else if(exitEff == Effect::ROTATE) {
|
|
|
|
// var rate = fff / (float) exitDur;
|
|
|
|
// view.setScaleX(1 - rate);
|
|
|
|
// view.setScaleY(view.getScaleX());
|
|
|
|
// view.setRotation(rate * 360);
|
|
|
|
// } else if(exitEff == Effect::ROTATE_R) {
|
|
|
|
// var rate = fff / (float) exitDur;
|
|
|
|
// view.setScaleX(1 - rate);
|
|
|
|
// view.setScaleY(view.getScaleX());
|
|
|
|
// view.setRotation(- rate * 360);
|
|
|
|
// }
|
|
|
|
// } else resetEff();
|
|
|
|
ff++;
|
|
|
|
}
|
|
|
|
void resetEff() {
|
|
|
|
// view.setTranslationX(0);
|
|
|
|
// view.setTranslationY(0);
|
|
|
|
// view.setAlpha(1);
|
|
|
|
// view.setScaleX(1);
|
|
|
|
// view.setScaleY(1);
|
|
|
|
// view.setRotation(0);
|
|
|
|
}
|
2023-10-23 14:58:29 +08:00
|
|
|
};
|
2024-02-21 18:08:50 +08:00
|
|
|
struct Layer {
|
|
|
|
std::vector<Source> srcs;
|
|
|
|
int64_t endMilli = LLONG_MAX;
|
|
|
|
int dur = 0;
|
|
|
|
bool isLoop = 0;
|
2023-04-18 14:14:46 +08:00
|
|
|
};
|
|
|
|
|
2024-02-21 18:08:50 +08:00
|
|
|
struct Page {
|
|
|
|
std::vector<Layer> layers;
|
|
|
|
int64_t endMilli = LLONG_MAX;
|
|
|
|
int sDur = 0, tDur = 0, repeatTimes = 0, audioDur = 0;
|
|
|
|
|
|
|
|
void hide() {
|
|
|
|
for(auto &layer : layers) for(auto &src : layer.srcs) src.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMillis(int64_t milli) {
|
|
|
|
endMilli = milli + sDur;
|
|
|
|
for(auto &layer : layers) {
|
|
|
|
if(layer.isLoop) layer.endMilli = milli + layer.dur;
|
|
|
|
for(auto &src : layer.srcs) {
|
|
|
|
src.endMilli = milli + src.endTime;
|
|
|
|
src.startMilli = milli + src.startTime;
|
|
|
|
if(src.startTime == 0) src.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-18 14:14:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class PlayWin : public QWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static PlayWin *self;
|
2023-10-23 14:58:29 +08:00
|
|
|
static PlayWin *newIns(int width, int height, QString dir, const JValue &prog, QWidget *parent = nullptr);
|
|
|
|
PlayWin(int x, int y, int width, int height, QString dir, const JValue &prog, QWidget *parent = nullptr);
|
2023-04-18 14:14:46 +08:00
|
|
|
|
2024-02-21 18:08:50 +08:00
|
|
|
QOpenGLWidget *gl;
|
2023-04-18 14:14:46 +08:00
|
|
|
int cur = 0;
|
2024-02-21 18:08:50 +08:00
|
|
|
std::vector<Page> pages;
|
|
|
|
std::vector<Page> avas;
|
|
|
|
int curAva = 0, curTimes = 1;
|
|
|
|
|
2023-04-18 14:14:46 +08:00
|
|
|
QPoint mPressRel;
|
|
|
|
QMenu *menu;
|
|
|
|
|
2024-02-21 18:08:50 +08:00
|
|
|
void doFrame();
|
|
|
|
|
2023-04-18 14:14:46 +08:00
|
|
|
protected:
|
|
|
|
void mousePressEvent(QMouseEvent *) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *) override;
|
|
|
|
void leaveEvent(QEvent *) override;
|
|
|
|
void contextMenuEvent(QContextMenuEvent *) override;
|
|
|
|
void closeEvent(QCloseEvent *) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PLAYWIN_H
|