diff options
author | louis <louis.braun@gmx.de> | 2015-05-10 12:55:23 +0200 |
---|---|---|
committer | louis <louis.braun@gmx.de> | 2015-05-10 12:55:23 +0200 |
commit | 28743412fed4d9d59100c38f4def327122ed0e2c (patch) | |
tree | abfca0011e69b0e39973de807b2b3e99ff7936bb /libcore | |
parent | c5edc10fbd57d17e774a07b659996bdffe16242c (diff) | |
download | vdr-plugin-skindesigner-28743412fed4d9d59100c38f4def327122ed0e2c.tar.gz vdr-plugin-skindesigner-28743412fed4d9d59100c38f4def327122ed0e2c.tar.bz2 |
expanded shifting features
Diffstat (limited to 'libcore')
-rw-r--r-- | libcore/pixmapcontainer.c | 163 | ||||
-rw-r--r-- | libcore/pixmapcontainer.h | 6 |
2 files changed, 155 insertions, 14 deletions
diff --git a/libcore/pixmapcontainer.c b/libcore/pixmapcontainer.c index 2f498e0..cab356e 100644 --- a/libcore/pixmapcontainer.c +++ b/libcore/pixmapcontainer.c @@ -1,4 +1,5 @@ #define __STL_CONFIG_H +#include <math.h> #include "pixmapcontainer.h" #include "../config.h" @@ -21,6 +22,8 @@ cPixmapContainer::cPixmapContainer(int numPixmaps) { checkRunning = false; fadeTime = 0; shiftTime = 0; + shiftType = stNone; + shiftMode = smLinear; deleteOsdOnExit = false; } @@ -349,8 +352,10 @@ void cPixmapContainer::FadeIn(void) { } return; } + int frames = fadeTime * config.framesPerSecond / 1000; + if (frames <= 0) frames = 1; + int frameTime = fadeTime / frames; uint64_t Start = cTimeMs::Now(); - int FadeFrameTime = fadeTime / 10; while (Running()) { uint64_t Now = cTimeMs::Now(); double t = min(double(Now - Start) / fadeTime, 1.0); @@ -367,18 +372,20 @@ void cPixmapContainer::FadeIn(void) { } DoFlush(); int Delta = cTimeMs::Now() - Now; - if (Running() && (Delta < FadeFrameTime)) - cCondWait::SleepMs(FadeFrameTime - Delta); + if (Running() && (Delta < frameTime)) + cCondWait::SleepMs(frameTime - Delta); if ((int)(Now - Start) > fadeTime) break; } } void cPixmapContainer::FadeOut(void) { - if (!fadeTime) + if (!fadeTime || IsAnimated()) return; + int frames = fadeTime * config.framesPerSecond / 1000; + if (frames <= 0) frames = 1; + int frameTime = fadeTime / frames; uint64_t Start = cTimeMs::Now(); - int FadeFrameTime = fadeTime / 10; while (true) { uint64_t Now = cTimeMs::Now(); double t = min(double(Now - Start) / fadeTime, 1.0); @@ -395,8 +402,8 @@ void cPixmapContainer::FadeOut(void) { } DoFlush(); int Delta = cTimeMs::Now() - Now; - if (Delta < FadeFrameTime) - cCondWait::SleepMs(FadeFrameTime - Delta); + if (Delta < frameTime) + cCondWait::SleepMs(frameTime - Delta); if ((int)(Now - Start) > fadeTime) break; } @@ -405,6 +412,137 @@ void cPixmapContainer::FadeOut(void) { void cPixmapContainer::ShiftIn(void) { if (shiftTime < 1) return; + + int frames = shiftTime * config.framesPerSecond / 1000; + if (frames <= 0) frames = 1; + int frameTime = shiftTime / frames; + + if (shiftType > stNone) { + ShiftInFromBorder(frames, frameTime); + } else { + ShiftInFromPoint(frames, frameTime); + } +} + +void cPixmapContainer::ShiftInFromBorder(int frames, int frameTime) { + //calculating union rectangle of all pixmaps viewports + cRect unionArea; + bool isNew = true; + for (int i = 0; i < numPixmaps; i++) { + if (!PixmapExists(i)) + continue; + if (isNew) { + unionArea = ViewPort(i); + isNew = false; + } else { + unionArea.Combine(ViewPort(i)); + } + } + //shifthing all pixmaps to dedicated start positions + cPoint startPositions[numPixmaps]; + int osdWidth = osd->Width(); + int osdHeight = osd->Height(); + int xStart = 0; + int yStart = 0; + for (int i = 0; i < numPixmaps; i++) { + if (!PixmapExists(i)) + continue; + cPoint pos; + Pos(i, pos); + switch (shiftType) { + case stLeft: + xStart = pos.X() - (unionArea.X() + unionArea.Width()); + pos.SetX(xStart); + break; + case stRight: + xStart = osdWidth + (pos.X() - unionArea.X()); + pos.SetX(xStart); + break; + case stTop: + yStart = pos.Y() - (unionArea.Y() + unionArea.Height()); + pos.SetY(yStart); + break; + case stBottom: + yStart = osdHeight + (pos.Y() - unionArea.Y()); + pos.SetY(yStart); + break; + default: + break; + } + startPositions[i] = pos; + cRect r = ViewPort(i); + r.SetPoint(pos.X(), pos.Y()); + SetViewPort(i, r); + SetAlpha(i, ALPHA_OPAQUE); + } + DoFlush(); + //Calculating total shifting distance + int shiftTotal = 0; + switch (shiftType) { + case stLeft: + shiftTotal = unionArea.X() + unionArea.Width(); + break; + case stRight: + shiftTotal = unionArea.Width() + (osdWidth - (unionArea.X() + unionArea.Width())); + break; + case stTop: + shiftTotal = unionArea.Y() + unionArea.Height(); + break; + case stBottom: + shiftTotal = unionArea.Height() + (osdHeight - (unionArea.Y() + unionArea.Height())); + break; + default: + break; + } + //Moving In + uint64_t Start = cTimeMs::Now(); + while (Running()) { + uint64_t Now = cTimeMs::Now(); + double t = min(double(Now - Start) / shiftTime, 1.0); + if (shiftMode == smSlowedDown) { + //using f(x) = -(x-1)^2 + 1 as mapping function + t = (-1)*pow(t - 1, 2) + 1; + } + int xNew = 0; + int yNew = 0; + for (int i = 0; i < numPixmaps; i++) { + if (!PixmapExists(i)) + continue; + cRect r = ViewPort(i); + switch (shiftType) { + case stLeft: + xNew = startPositions[i].X() + t * shiftTotal; + r.SetPoint(xNew, r.Y()); + break; + case stRight: + xNew = startPositions[i].X() - t * shiftTotal; + r.SetPoint(xNew, r.Y()); + break; + case stTop: + yNew = startPositions[i].Y() + t * shiftTotal; + r.SetPoint(r.X(), yNew); + break; + case stBottom: + yNew = startPositions[i].Y() - t * shiftTotal; + r.SetPoint(r.X(), yNew); + break; + default: + break; + } + SetViewPort(i, r); + } + DoFlush(); + int Delta = cTimeMs::Now() - Now; + if (Running() && (Delta < frameTime)) { + cCondWait::SleepMs(frameTime - Delta); + } + if ((int)(Now - Start) > shiftTime) + break; + } +} + +void cPixmapContainer::ShiftInFromPoint(int frames, int frameTime) { + //store original positions of pixmaps and move to StartPosition cPoint destPos[numPixmaps]; for (int i = 0; i < numPixmaps; i++) { if (!PixmapExists(i)) @@ -418,12 +556,9 @@ void cPixmapContainer::ShiftIn(void) { SetAlpha(i, ALPHA_OPAQUE); } DoFlush(); - - int frames = shiftTime / 20; - if (frames <= 0) frames = 1; + //Move In uint64_t Start = cTimeMs::Now(); - int frameTime = shiftTime / frames; - while (true) { + while (Running()) { uint64_t Now = cTimeMs::Now(); double t = min(double(Now - Start) / shiftTime, 1.0); for (int i = 0; i < numPixmaps; i++) { @@ -437,14 +572,14 @@ void cPixmapContainer::ShiftIn(void) { } DoFlush(); int Delta = cTimeMs::Now() - Now; - if (Delta < frameTime) + if (Running() && (Delta < frameTime)) cCondWait::SleepMs(frameTime - Delta); if ((int)(Now - Start) > shiftTime) break; } - } + /***************************************** * scrollSpeed: 1 slow * 2 medium diff --git a/libcore/pixmapcontainer.h b/libcore/pixmapcontainer.h index d17753c..e924126 100644 --- a/libcore/pixmapcontainer.h +++ b/libcore/pixmapcontainer.h @@ -24,8 +24,12 @@ private: bool checkRunning; int fadeTime; int shiftTime; + int shiftType; + int shiftMode; cPoint startPos; bool deleteOsdOnExit; + void ShiftInFromBorder(int frames, int frameTime); + void ShiftInFromPoint(int frames, int frameTime); protected: void SetInitFinished(void) { pixContainerInit = false; }; bool CreateOsd(int Left, int Top, int Width, int Height); @@ -61,6 +65,8 @@ protected: //HELPERS -- do not access the pixmaps array directly, use wrapper functions void SetFadeTime(int fade) { fadeTime = fade; }; void SetShiftTime(int shift) { shiftTime = shift; }; + void SetShiftType(int type) { shiftType = type; }; + void SetShiftMode(int mode) { shiftMode = mode; }; void SetStartPos(int posX, int posY) { startPos.SetX(posX); startPos.SetY(posY); }; bool IsAnimated(void) { return (shiftTime > 0); }; void FadeIn(void); |