mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
RasterPlayer: Included default single threaded
git-svn-id: svn://ultimatepp.org/upp/trunk@2675 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
86cd6af88d
commit
0d7a84167d
4 changed files with 79 additions and 25 deletions
|
|
@ -38,6 +38,7 @@ RasterPlayer::RasterPlayer() {
|
|||
running = 0;
|
||||
kill = 1;
|
||||
speed = 1;
|
||||
mt = false;
|
||||
}
|
||||
|
||||
void RasterPlayer::Paint(Draw& w) {
|
||||
|
|
@ -78,7 +79,7 @@ bool RasterPlayer::LoadBuffer(const String &buffer) {
|
|||
case 1:
|
||||
case 2: iw.DrawRect(r, White());
|
||||
break;
|
||||
//case 2: iw.DrawRect(sz, White()); // It seems files do no comply with standard
|
||||
//case 2: iw.DrawRect(sz, White()); // It seems gif files do not comply with standard
|
||||
// break;
|
||||
case 4: if (i > 0)
|
||||
previous = ::GetRect(images[i-1], r);
|
||||
|
|
@ -98,6 +99,7 @@ bool RasterPlayer::Load(const String &fileName) {
|
|||
return LoadBuffer(LoadStream(in));
|
||||
}
|
||||
|
||||
#ifdef _MULTITHREADED
|
||||
void RasterPlayerThread(RasterPlayer *animatedClip) {
|
||||
TimeStop t;
|
||||
dword tFrame = 0;
|
||||
|
|
@ -108,7 +110,7 @@ void RasterPlayerThread(RasterPlayer *animatedClip) {
|
|||
ind = 0;
|
||||
tFrame += dword(animatedClip->delays[ind]/animatedClip->speed);
|
||||
}
|
||||
while (t.Elapsed() < tFrame)
|
||||
while (t.Elapsed() < tFrame && !animatedClip->kill)
|
||||
Sleep(10);
|
||||
PostCallback(callback(animatedClip, &RasterPlayer::NextFrame));
|
||||
}
|
||||
|
|
@ -116,6 +118,20 @@ void RasterPlayerThread(RasterPlayer *animatedClip) {
|
|||
animatedClip->running = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void RasterPlayer::TimerFun() {
|
||||
if (kill || !running)
|
||||
return;
|
||||
|
||||
if (tTime.Elapsed() < tFrame)
|
||||
return;
|
||||
int iFrame = ind+1;
|
||||
if (iFrame > GetPageCount()-1)
|
||||
iFrame = 0;
|
||||
tFrame += dword(delays[iFrame]/speed);
|
||||
NextFrame();
|
||||
}
|
||||
|
||||
void RasterPlayer::Play() {
|
||||
if (images.GetCount() <= 1)
|
||||
|
|
@ -124,15 +140,44 @@ void RasterPlayer::Play() {
|
|||
running = true;
|
||||
kill = false;
|
||||
}
|
||||
Thread().Run(callback1(RasterPlayerThread, this));
|
||||
#ifdef _MULTITHREADED
|
||||
if (mt)
|
||||
Thread().Run(callback1(RasterPlayerThread, this));
|
||||
else
|
||||
#endif
|
||||
{
|
||||
tFrame = 0;
|
||||
tTime.Reset();
|
||||
SetTimeCallback(-50, callback(this, &RasterPlayer::TimerFun), 1);
|
||||
}
|
||||
}
|
||||
|
||||
void RasterPlayer::Stop() {
|
||||
INTERLOCKED_(mutex) {
|
||||
kill = true;
|
||||
}
|
||||
while (running)
|
||||
Sleep(10);
|
||||
#ifdef _MULTITHREADED
|
||||
if (mt) {
|
||||
while (running)
|
||||
Sleep(10);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
KillTimeCallback(1);
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
|
||||
RasterPlayer& RasterPlayer::SetMT(bool _mt) {
|
||||
bool wasrunning;
|
||||
INTERLOCKED_(mutex) {
|
||||
wasrunning = running;
|
||||
}
|
||||
Stop();
|
||||
mt = _mt;
|
||||
if (wasrunning)
|
||||
Play();
|
||||
return *this;
|
||||
}
|
||||
|
||||
RasterPlayer::~RasterPlayer() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef _AnimatedClip_AnimatedClip_h_
|
||||
#define _AnimatedClip_AnimatedClip_h_
|
||||
#ifndef _RasterPlayer_RasterPlayer_h_
|
||||
#define _RasterPlayer_RasterPlayer_h_
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
|
|
@ -14,7 +14,12 @@ private:
|
|||
int ind;
|
||||
Color background;
|
||||
double speed;
|
||||
|
||||
bool mt;
|
||||
|
||||
TimeStop tTime;
|
||||
dword tFrame;
|
||||
|
||||
|
||||
public:
|
||||
RasterPlayer();
|
||||
~RasterPlayer();
|
||||
|
|
@ -28,6 +33,7 @@ public:
|
|||
inline void NextPage() {NextFrame();};
|
||||
RasterPlayer& SetBackground(Color c) {background = c; Refresh(); return *this;}
|
||||
RasterPlayer& SetSpeed(double s = 1) {speed = s; Refresh(); return *this;}
|
||||
RasterPlayer& SetMT(bool _mt = false);
|
||||
|
||||
Callback WhenShown;
|
||||
|
||||
|
|
@ -35,9 +41,12 @@ public:
|
|||
int GetFrameCount() {return images.GetCount();};
|
||||
int GetPage() {return ind;};
|
||||
void SetPage(int i) {ind = minmax(i, 0, images.GetCount());};
|
||||
|
||||
|
||||
#ifdef _MULTITHREADED
|
||||
friend void RasterPlayerThread(RasterPlayer *animatedClip);
|
||||
|
||||
#endif
|
||||
void TimerFun();
|
||||
|
||||
protected:
|
||||
volatile Atomic running, kill;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
description "Control to show animated .gif and .tiff files\377";
|
||||
|
||||
uses
|
||||
plugin\gif,
|
||||
plugin\tif;
|
||||
|
||||
file
|
||||
RasterPlayer.h,
|
||||
RasterPlayer.cpp,
|
||||
RasterPlayer.iml,
|
||||
RasterPlayer.usc,
|
||||
Credits.txt;
|
||||
|
||||
description "Control to show animated .gif and .tiff files\377";
|
||||
|
||||
uses
|
||||
plugin\gif,
|
||||
plugin\tif;
|
||||
|
||||
file
|
||||
RasterPlayer.cpp,
|
||||
RasterPlayer.h,
|
||||
RasterPlayer.iml,
|
||||
RasterPlayer.usc,
|
||||
Credits.txt;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef _RasterPlayer_icpp_init_stub
|
||||
#define _RasterPlayer_icpp_init_stub
|
||||
#ifndef _AnimatedClip_icpp_init_stub
|
||||
#define _AnimatedClip_icpp_init_stub
|
||||
#include "plugin\gif/init"
|
||||
#include "plugin\tif/init"
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue